Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

(dkubb) Re: (2) Searching for files

by dkubb (Deacon)
on Mar 19, 2001 at 08:57 UTC ( [id://65364]=note: print w/replies, xml ) Need Help??


in reply to Searching for files

You might want to examine your regex, you're using a dot inside the filename, which will match one of anything. You may want to escape it using a backslash (\), to make it a literal match. Or better yet, don't use a regex at all, try using eq.

Also, File::find() will execute getpm() for each file it finds underneath $fpath. More than likely, the first file it's finding is not readme.txt, so it's printing "File not Found", and exiting.

If you'd like the behaviour of printing "File Not Found" if there is no match, a better idea would be to push any file matches onto an array, then test the array after you're done directory traversing:

#!/usr/bin/perl -w use strict; use File::Find; use vars qw(@FILES); find(\&getpm, '.'); unless(@FILES) { print "File not Found\n"; exit; } print "$_\n" for @FILES; sub getpm { push @FILES, $File::Find::name if -f && $_ eq 'readme.txt'; };

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found