Hi,

I here is a sample of the problem I am trying to solve.

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, open a directory handle and try to compare the value to the right of the pipe to the file names in the directory. 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. It seems like the all the contents of the file index are run against one iteration of the directory contents then it quits.

I have changed the list assignment from the split function to an array and added a foreach loop there but that seems to provide the same output.

Here is a copy of my current code snippet:

#!/usr/bin/perl
#

use strict;
use warnings;

my $index = "/tmp/www/index.txt";
my $pdf_dir = "/tmp/www";

open (INDEX, "$index") || die "Can't open $index: $!\n";
opendir (PDFDIR, $pdf_dir) || die "Can't open $pdf_dir: $!\n";

while (my $line = <INDEX> ) {
        chomp $line;
        my ($raw_name, $std_name)  = (split /\|/, $line);
        if (grep {$std_name} readdir(PDFDIR)) {
        print "I found this: $std_name\n";
        }
}

Thanks,

-Angus

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


Reply via email to