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

Re^2: File::Find preprocess

by pvaldes (Chaplain)
on Jan 08, 2018 at 16:42 UTC ( [id://1206913]=note: print w/replies, xml ) Need Help??


in reply to Re: File::Find preprocess
in thread File::Find preprocess

And more strange, If I change the function wanted like this:

sub when { print $File::Find::name," "; }

I obtain: ". hi ./1 bye", even if the file "1" does not exist

Updated: I mean file::find, not find::file

Replies are listed 'Best First'.
Re^3: File::Find preprocess
by stevieb (Canon) on Jan 08, 2018 at 16:50 UTC

    Per the documentation, preprocess receives a list (of entries in the current directory), and is expected to return a list (of entries). The purpose for this functionality is to provide you the ability to prune, filter, reorganize etc the list of entries as you sweep over them before the wanted function is called (it receives the list returned from preprocess).

    The most basic test you can do is just immediately return the list the begin function receives:

    sub begin { my @entries = @_; print "begin\n"; return @entries; }

    The reason you're getting "1", is because that's what a successful print statement returns, and in Perl, if you don't have an explicit return(), the result of the last expression evaluated is returned (in your case, the result of the print, meaning "1").

    my $x = print "hi\n"; print "$x\n"; __END__ hi 1

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1206913]
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: (6)
As of 2024-03-28 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found