pvaldes has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: File::Find preprocess
by tybalt89 (Monsignor) on Jan 08, 2018 at 17:13 UTC | |
Re: File::Find preprocess
by karlgoethebier (Abbot) on Jan 08, 2018 at 16:26 UTC | |
Re: File::Find preprocess
by pvaldes (Chaplain) on Jan 08, 2018 at 16:33 UTC | |
by stevieb (Canon) on Jan 08, 2018 at 16:58 UTC | |
by pvaldes (Chaplain) on Jan 08, 2018 at 17:13 UTC | |
by stevieb (Canon) on Jan 08, 2018 at 17:20 UTC | |
by pvaldes (Chaplain) on Jan 08, 2018 at 17:26 UTC | |
by pvaldes (Chaplain) on Jan 08, 2018 at 16:42 UTC | |
by stevieb (Canon) on Jan 08, 2018 at 16:50 UTC |