Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://389538]
help
Chatterbox?
[Corion]: I think I'm overdesigning things again. I want to export(later, synchronize) data from Google Keep, by scraping the HTML. And I'm thinking of automating this by having a canary note whose text my program knows and from which it can determine the ...
[Corion]: ... surrounding HTML to scrape all the other notes. Maybe I should better look at dumping all the requests that pass between Google and my "browser" instead.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2017-12-12 08:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (327 votes). Check out past polls.

    Notices?