Lets suppose that we have a dir A with two subdirs B and C each one having two files on it named: a1, a2, b1, b2, and, c1, c2. I'm using File::Find to traverse the entire tree
My goal is to explore the preprocess and postprocess options in the function find from this module. My dumb function should print "hi" each time I enter in a dir, "bye" each time I finish with this directory and "file! " for each file present in the dir:
#!/usr/bin/perl -w
use strict;
use File::Find;
my $dir = '.';
find({preprocess => \&before, wanted => \&when, postprocess => \&after
+}, $dir);
sub before {
print "hi ";
exit 0;
}
sub after {
print "bye ";
}
sub when {
print "file! ";
return;
}
I expect having printed three "hi", three "bye" and six "file!" in this order: hi file! file! bye (repeated three times);
I obtain instead just "file! hi", and the same if I change "exit 0;" by "exit 1;" Can somebody please explain why?