Angus Glanville wrote:
I have an index.txt file that contains two values separated by a pipe
symbol like this:
junk_file_test1|test1.pdf
junk_file_test2|test2.pdf
I slurp the file in,
That not what you do in the code you posted.
open a directory handle and try to compare the
value to the right of the pipe to the file names in the directory.
Storing the file names in a hash makes later comparisons easier.
My
final goal is to normalize the names so that they are the same case on
the file system as indicated in the index file. I think this will be a
simple rename. however, at this point when I run through my while loop
I only get one file name output when the script ends, but I expect to
see multiple matches.
<snip>
while (my $line = <INDEX> ) {
chomp $line;
my ($raw_name, $std_name) = (split /\|/, $line);
if (grep {$std_name} readdir(PDFDIR)) {
That empties PDFDIR at the first iteration of the while loop, which is
why you only get one match.
Please consider this example:
# store file names in hash
open my $INDEX, '<', $index or die "Can't open $index: $!";
my %std_names;
while ( <$INDEX> ) {
my ($name) = /\|(.+)/ or die 'Parsing failed';
$std_names{ lc $name } = $name;
}
# process directory
chdir $pdf_dir or die $!;
opendir my $PDFDIR, $pdf_dir or die "Can't open $pdf_dir: $!";
while ( my $file = readdir $PDFDIR ) {
if ( $std_names{ lc $file } ) {
rename $file, $std_names{ lc $file } or die $!;
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/