Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: File test in grep not excluding current directory (chdir)

by tye (Sage)
on Jul 01, 2014 at 13:41 UTC ( [id://1091844]=note: print w/replies, xml ) Need Help??


in reply to File test in grep not excluding current directory

The File::Find documentation says that 'preprocess' is meant for things that care only about the name. Doing file test operators is exactly the kind of thing that they are saying you should not do in 'preprocess'.

'preprocess' happens before chdir is called. So the only reason you would get "File1" in the output would be if you have "File1" in both a directory and a subdirectory of that directory.

Writing out $File::Find::name as well was $_ shows why you get "." with your second code. 'preprocess' is called after readdir(). Before you even get to readdir(), File::Find chdir()s into the directory you passed in and processes that directory itself, passing '.' to your 'wanted' sub.

- tye        

Replies are listed 'Best First'.
Re^2: File test in grep not excluding current directory (chdir)
by GotToBTru (Prior) on Jul 01, 2014 at 14:14 UTC

    I can verify that it calls wanted before preprocess - but why? The docs indicate otherwise:

    "Your preprocessing function is called after readdir(), but before the loop that calls the wanted() function. It is called with a list of strings (actually file/directory names) and is expected to return a list of strings. The code can be used to sort the file/directory names alphabetically, numerically, or to filter out directory entries based on their name alone."

    That says to me that it filters before looping, which is exactly what I would expect, except it doesn't. Okay, lesson learned.

    1 Peter 4:10

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-03-28 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found