On Mon, Jul 14, 2003 at 06:01:33AM -1000, Beau E. Cox wrote:
> From: "Beau E. Cox" <[EMAIL PROTECTED]>
> >
> > Any way to stop File::Find's directory scanning
> > from the 'wanted' sucroutine?
>
> Well... here's what I ended up doing:
>
> ...
> eval {
> find (\&wanted, $source);
> };
> if ($@ && $@ !~ /__exit__/) {
> print STDERR "[EMAIL PROTECTED]";
> exit 8;
> }
> ...
> sub wanted
> {
> die "__exit__" if <some test>;
> ...
> }
>
> Sorta non-cool, but it works. Anyone else have a
> better idea?
There are (at least) two other ways.
This will stop File::Find from recursing, which gets you out of
the loop almost as quickly as die(), and with a bit more style:
sub wanted {
if (condition) {
$File::Find::prune++;
return;
}
...
}
And this jumps out immediately (like die()) but it seems less
readable and more fragile than the other two.
sub wanted {
last FILE if condition;
...
}
FILE: { find \&wanted, $dir }
--
Steve
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]