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

Does File::Find always visit files before subdirs?

by Anonymous Monk
on Aug 05, 2012 at 00:11 UTC ( [id://985467]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Empirically, File::Find (with follow_fast=>1 seems to call wanted() for all files in a directory before any subdirectories.
But the documentation doesn't mention that behavior.

Is this a documentation omission, or just an implementation quirk? In other words, is it guaranteed that files will always be visited before subdirectories?

For example, if I want to visit subdirs only if the parent dir contains a certain marker file, then I could set $File::Find::prune=1 when each subdir is visited unless the marker file has been seen. But only if the above "rule" is really a rule.

Replies are listed 'Best First'.
Re: Does File::Find always visit files before subdirs?
by ig (Vicar) on Aug 05, 2012 at 06:38 UTC
    is it guaranteed that files will always be visited before subdirectories?

    Who's guarantee would you trust?

    You have access to the code and it is not complicated. The version I have would do as you say quite reliably. A good test suite for your own application and use of File::Find might give you your best "guarantee".

Re: Does File::Find always visit files before subdirs?
by BillKSmith (Monsignor) on Aug 05, 2012 at 04:05 UTC

    I believe that you can do what you want with a preprocess filter in %options. Details of the modules internal processing would not matter. Refer: File::Find

Re: Does File::Find always visit files before subdirs?
by zentara (Archbishop) on Aug 05, 2012 at 12:48 UTC
Re: Does File::Find always visit files before subdirs?
by Anonymous Monk on Aug 05, 2012 at 16:25 UTC
    I would not make that assumption. The "correct" behavior of your program should not be a side-effect: your code should be such that it compels the right behavior to occur, and such that it is abundantly clear what the right behavior is supposed to be. If you need to find directories first, then go find only-directories first. Then, go find files ignoring directories. If the module says that the behavior you are looking for is or can be guaranteed, explicitly mention that guarantee in your source-code, and if an option controls it, explicitly set that option even if it's currently the default. Packages do change their behavior sometimes. Sometimes by design; sometimes because they never promised you a rose-garden in the first place.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found