> -----Original Message----- > From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] > Sent: Friday, July 22, 2005 11:44 AM > To: Brian Volk > Cc: Beginners (E-mail) > Subject: Re: File::Find if match rename > > > On Jul 22, Brian Volk said: > > > I have two text files and I have a directory of .pdf files > that are named > > 00020.pdf 00035.pdf 00040.pdf 00067.pdf. ( same as records > in file_2 ) What > > I need to do is look at each record in file_2 and see if > the .pdf file > > exist.. if so copy that file to a new directory and rename > it to the > > corresponding record in file one for example; the first > value 00020 would > > be renamed ( if file exits ) to 70624.pdf and the second > value 00020 would > > be renamed 70280.pdf ...Which would actually be the same > .pdf file just w/ a > > If the PDF files are in a given directory (and not hidden in various > locations further down that directory's subdirectories) then > you won't > need File::Find. I would also be a little wary of renaming files as > File::Find was operating. I personally don't know if that > would have an > effect, but I would stay clear of it myself. > > As for your data structures, you *could* create a hash, but I > don't think > there's necessarily a need for it. Have two parallel arrays > isn't so bad > in this case. However, the way I see it, you don't need > arrays at all. > > Here's how I would solve the problem: > > #!/usr/bin/perl > > use strict; # I was very happy to see > use warnings; # you had these in your code > > my $item_file = "c:/brian/spartan/hp_items.txt"; > my $mfg_file = "c:/brian/spartan/mfg_num.txt"; > my $src_dir = "c:/spartan/msds/number"; # source directory > my $dst_dir = "c:/brian/spartan"; # destination directory > > open ITEM, "< $item_file" or die "can't read $item_file: $!"; > open MFG, "< $mfg_file" or die "can't read $mfg_file: $!"; > > while (my $old = <MFG>) { > my $new = <ITEM>; > chomp($old, $new); > > if (-e "$src_dir/$old") { > rename "$src_dir/$old" => "$dst_dir/$new" > or warn "can't rename $src_dir/$old to $dst_dir/$new: $!"; > } > } > > -- > Jeff "japhy" Pinyan % How can we ever be the sold short or > RPI Acacia Brother #734 % the cheated, we who for every service > http://japhy.perlmonk.org/ % have long ago been overpaid? > http://www.perlmonks.org/ % -- Meister Eckhart
Wow! Thank you very much! It is spelled out plain as day on page 89 of Learning Perl, ugh! :~) ---- Chapter 6 I/O Basics, Input from the Diamond Operator ----- while (defined($line = <>)) { chomp(line); print "It was $line that I saw!\n"; } So, if we run this program w/ the invocation arguments fred, it will say something like: "It was [a line from file fred] that I saw!", "It was [another line from fred] that I saw!" on and on until it reaches the end of the file. ---- End of Quote --- Thanks again it worked great! 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>