eff_i_g has asked for the wisdom of the Perl Monks concerning the following question:
I've a maintenance script that uses File::Find::Rule (FFR) to traverse thousands of directories. Since I may need to stop the script in midstream I've incorporated sigtrap to set a variable that FFR can utilize.
The issue is this: I cannot find a way to truly stop FFR. I can use the variable in a rule that tells FFR to skip the remaining files (see the code below), but what if the signal arrives at file 1,000 and there are 10,000 more to go? It's not going to stop; it's going to skip 10,000 more files.
use strict; use warnings; use File::Find::Rule; use sigtrap 'handler' => \&abort, 'any'; ### So I can set up a kill command for testing. print $$, "\n"; <>; my $continue = 1; sub abort { print "Exiting...\n"; $continue = 0; } File::Find::Rule->exec(sub { return $continue }) ->directory ->exec( sub { print $_[2], "\n"; } ) ->in('/wherever');
I could use FFR's start/match combo to achieve this, but this has the side effect of arraying everything before the process even begins.
Have I missed something in the docs? Is there a way to achieve this without resorting to some homegrown opendir contraption?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Stopping File::Find::Rule
by zentara (Cardinal) on Oct 15, 2010 at 21:23 UTC | |
|
Re: Stopping File::Find::Rule
by runrig (Abbot) on Oct 15, 2010 at 21:16 UTC |