Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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