Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Get Filename using perl

by Rhys (Pilgrim)
on Sep 09, 2004 at 02:23 UTC ( #389538=note: print w/replies, xml ) Need Help??

in reply to Get Filename using perl

The Perl grep returns the matching contents from the file, not the file name, so your code should be more like:

opendir (DIR, "$responseDir") or die "could not open $responseDir :$!\ +n"; foreach $file ( readdir(DIR) ) { open THISFILE, "$responseDir/$file"; my @newFile = grep { /$commonField/ } <THISFILE>; if ( @newFile ) { # If there were any contents, this is our file. $matchedfile = $file; close THISFILE; last; } close THISFILE; } closedir(DIR); print "Matched file $matchedfile.\n";

I tested a slight variation of this. You'll definitely want to re-test this, but I think it works.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://389538]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2016-10-27 05:25 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (353 votes). Check out past polls.