Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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.

--J


Comment on Re: Get Filename using perl
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2014-09-21 04:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls