in reply to Get Filename using perl

BTW.. this is what i am trying and it's not working
opendir (DIR, "$responseDir") or die "could not open $responseDir :$!\ +n"; my @newFile = grep { $commonField -f $responseDir/$_ } readdir(DIR); closedir(DIR);

Replies are listed 'Best First'.
Re^2: Get Filename using perl
by tachyon (Chancellor) on Sep 09, 2004 at 04:22 UTC

    grep and glob are often very useful, for example:

    my $dir = '.'; my $match = 'perl'; my @files = grep { -f } glob ( "$dir/*" ); for my $file(@files) { open my $fh, $file or next; print "Found match in $file\n" if grep{ /\Q$match\E/ }<$fh>; }

    cheers

    tachyon

Re^2: Get Filename using perl
by sgifford (Prior) on Sep 09, 2004 at 03:11 UTC
    readdir returns the names of files, not their contents, so you're actually searching for files whose name matchs your keyword.