Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Strange behavior in File::Find (stopped working for no reason)

by choroba (Cardinal)
on Apr 12, 2021 at 16:58 UTC ( [id://11131150]=note: print w/replies, xml ) Need Help??


in reply to Strange behavior in File::Find (stopped working for no reason)

Let's read the documentation.

> "preprocess"
The value should be a code reference. This code reference is used to preprocess the current directory. The name of the currently processed directory is in $File::Find::dir. 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. When follow or follow_fast are in effect, "preprocess" is a no-op.

Your preprocess subroutine, hi, returns an empty list, so there are no files too iterate over.

Why wasn't the preprocess subroutine called before wanted? Because the directory argument to find() is not preprocessed, wanted is run on it directly. Only the directories' contents that are subject to readdir are preprocessed.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^2: Strange behavior in File::Find (stopped working for no reason)
by pvaldes (Chaplain) on Apr 12, 2021 at 17:08 UTC

    Thanks Choroba. Solved. Now I need to put a nice glob in &hi and... voila! That solves my main problem with the real script

Log In?
Username:
Password:

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

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

    No recent polls found