> -----Original Message-----
> From: John Doe [mailto:[EMAIL PROTECTED]
> Sent: Thursday, August 04, 2005 8:03 AM
> To: beginners@perl.org
> Subject: Re: match basename file and s / / /;
> 
> 
> Brian Volk am Mittwoch, 3. August 2005 17.50:
> > Hi All~
> >
> > my program below is not returning any errors but nothing is 
> happening to
> > the .txt files like I hoped.  Can someone pls take a look 
> and let me know
> > what I'm doing wrong.
> >
> > ----- Thank you! ----
> >
> > # If there is a .pdf file and a matching .txt file, open 
> the .txt file and
> > s %  http://.*  %  "$link"  %
> >
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> > use File::Basename;
> >
> > my $pdf_dir = "j:/flash_host/ecomm/descriptions/product/MSDS";
> >     opendir(PDFDIR, $pdf_dir) or die "Can't open the 
> $pdf_dir: $!\n";
> >
> > # read file/directory names in that directory into @pdfs
> >
> > my @pdfs = readdir(PDFDIR) or die "Unable to read current dir:$!\n";
> >
> > closedir(PDFDIR);
> >
> > my $text_dir = "c:/brian/descriptions/product/small";
> >     opendir (TEXTDIR, $text_dir) or die "Can't open $text_dir: $!";
> >
> > # read all the .txt files and load @ARGV for <> operator
> >
> > @ARGV = map { "$text_dir/$_" } grep { !/^\./ } readdir TEXTDIR;
> >
> > my %PDFDIR_LIST;
> >
> > $PDFDIR_LIST{$_}=1 for @pdfs;
    $^I = '.bak';  #  I added this....
> > foreach my $text_file (<>) {
> 
> This tries to open and read the files whose names are 
> specified in @ARGV:
> 
> $ perl
> local @ARGV=(qw /a b c/);
> while (<>) {print};
> 
> Can't open a: No such file or directory at - line 2.
> Can't open b: No such file or directory at - line 2.
> Can't open c: No such file or directory at - line 2.
> 

Thank you for the reply but I don't think I understand..  The .txt files
that I am loading into @ARGV are the files that I want to open and
substitute the URL for a local path.... I thought that I had to include the
foreach $text_file so I could match the basename of the .txt file and .pdf
file and then include the "$basename.pdf" in the $link...  I'm pretty sure I
am matching the file up correctly but the .txt file are being erased instead
of sub'ing the url w/ the local path...   I think I'm confused... :~)

> >
> >         my ($basename, $suffix) = fileparse($text_file,'.txt');
> >  my $link = "descriptions/product/small/$basename.pdf";
> >
> >  if( $PDFDIR_LIST{"$basename.pdf"} ){
> >  open FH, $text_file or die "can't open $text_file: $!";
> >         s% http://.* % $link %;
                print; # I added this too..
> >         next;}
> >
> >  }
> > close (FH);
> > closedir (TEXTDIR);
> >
> > __END__
> 
> hth, joe
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to