Hi all,
file_1( item_nums ) file_2 ( mfg_nums )
70624.pdf 00020.pdf
70280.pdf 00020.pdf
70387.pdf 00020.pdf
70207.pdf 00035.pdf
30317.pdf 00035.pdf
70777.pdf 00040.pdf
70332.pdf 00067.pdf
70445.pdf 00067.pdf
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
different name... Below is what I have so far... I not getting any errors
but nothing is happening.? Any hints or suggestions would be greatly
appreciated. I was also thinking a hash may be better since I have unique
records in file 1... not sure...
#!/usr/bin/perl -w
use strict;
use File::Find;
my $item_nums = 'c:/brian/spartan/hp_items.txt' ;
my $mfg_nums ='c:/brian/spartan/mfg_num.txt' ;
open(ITEM_NUMS, "<", $item_nums) or die "couldn't read item_nums: $!";
open(MFG_NUMS, "<", $mfg_nums) or die "couldn't read mfg_nums: $!";
my @item_nums = <ITEM_NUMS> ;
my @mfg_nums = <MFG_NUMS>;
close(ITEM_NUMS);
close(MFG_NUMS);
find(\&wanted, 'c:/Spartan/MSDS/number');
sub wanted {
while (@mfg_nums) {
my $mfg_num = shift(@mfg_nums);
chomp $mfg_num;
my $new_pdf = shift(@item_nums);
chomp $new_pdf;
if ( m/$mfg_num/ ) {
rename "$_", "c:/brian/spartan/$new_pdf"
}
}
}
Thanks!
Brian Volk
HP Products
317.298.9950 x1245
<mailto:[EMAIL PROTECTED]> [EMAIL PROTECTED]