Monks,

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!


In reply to Stopping File::Find::Rule by eff_i_g

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.