No. The problem here is that you aren't completely reading documentation.
exit exits an entire process stack (ie. your program). return does leave the subroutine.
This, combined with the preprocess misconception is what's causing your issues.
| [reply] [d/l] [select] |
Hum, I see. I was expecting an equivalent to the "previously" condition in a common-lisp loop structure. A chunk of code that happens only once before the main body of the function starts iterating. I understand that if I need to do something within each subdirectory (check if something happens inside each subdir first), I would need then to traverse the tree two times using two different find functions. One for directories only, and a second for all files. Right? can't be done in one take?
| [reply] |
sub wanted {
if (-d){
print "directory\n";
}
if (-f){
print "file\n";
}
}
| [reply] [d/l] |
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 | [reply] [d/l] |
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
| [reply] [d/l] [select] |