RICHARDS, JIM wrote:
I am trying to compare files names listed in a file to the actual files
in a directory.  My code is as follows:

Your "code" won't compile. Please add the following two lines:

use warnings;
use strict;

to the top of your program and let perl help you find the mistakes.


The best bet to solve your problem is to use a hash for the file names, something like:


my $filelist = '/home/jim/filelist';
open FILES, '<', $filelist or die "Cannot open $filelist: $!";
my %files;
while ( <FILES> ) {
    chomp;
    $files{ $_ }++;
    }
close FILES;

my $dir = '/home/jim/somedir';
opendir DIR, $dir or die "Cannot open $dir: $!";
while ( my $file = readdir DIR ) {
    if ( exists $files{ $file } ) {
        print "$file\n";
        }
    }
closedir DIR;



John
--
use Perl;
program
fulfillment

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