---- Adam Wuellner <[EMAIL PROTECTED]> wrote:
>
> On 8/4/05, Brian Volk <[EMAIL PROTECTED]> wrote:
> > for now it's back to the drawing board and waiting for that light in my head
> > to go off!  :~)
> 
> Brian,
> 
> I took the last script you posted and re wrote it the way I would have
> gone about it.  It doesn't use in-place editing, or @ARGV, because I
> don't quite grasp how to make that work in this situation.  Anyway,
> see if it helps...  I apologize if there are errors, I couldn't
> quickly think of a way to test it.
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> use File::Basename;
> use File::Copy;
> 
> my $pdf_dir = "j:/flash_host/ecomm/descriptions/product/MSDS";
> # read file/directory names in that directory into @pdfs
> opendir PDFDIR, $pdf_dir 
>                       or die "Can't opendir $pdf_dir: $!\n";
> my @pdfs = readdir(PDFDIR);
> closedir PDFDIR;
> 
> my $text_dir = "c:/brian/descriptions/product/small";
> opendir TEXTDIR, $text_dir
>                       or die "Can't opendir $text_dir: $!";
> my @txts = map { "$text_dir/$_" } grep { !/^\./ } readdir TEXTDIR;
> closedir TEXTDIR;
> 
> my %PDFDIR_LIST;
> $PDFDIR_LIST{$_}=1 for @pdfs;
> 
> foreach my $text_file (@txts) {
>       my ($basename, $suffix) = fileparse($text_file,'.txt');
>       my $link = "descriptions/product/small/$basename.pdf";
>       
>       if( $PDFDIR_LIST{"$basename.pdf"} ) {
                my $out_file = "$textfile.new"; # just missed the underscore
>               open INPUT, "< $text_file" 
>                                       or die "can't open $text_file: $!";
>               open OUTPUT, "> $out_file" 
>                                       or die "can't open $out_file: $!";
>               
>               while (<INPUT>) {
>                       s% http://.* % $link %;  # are you sure you don't need 
> the g option?
>                       print OUTPUT;
>               }
>               close INPUT; close OUTPUT;
>               move( $text_file, "$text_file.bak" );
>               move( $out_file, $text_file );
>       }
> }
> 
> __END__
> 
> -- 
> Adam Wuellner
> 
Adam.. you're a saint! +<:-) That work perfectly!   I knew I had to use 
"foreach" for the $basename to work correctly and I was able to get the 
subsitution to work when I used while <>  ...I just couldn't figure out how  to 
incorporate both of them...  I DO NOW! Thank you very much! 

John and Jay thank you guys as well for teaching me.. I really am learning a 
lot! 

Brian Volk

--
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