in reply to File::Find exit

File::Find will short-circuit, there is no need to change your code significantly. What you can do is to wrap the find calls in an evaluation block like below -
my @nod; eval { sub foo {die if (/^p/i); push @nod, $_} find (\&foo, "./"); }; print "$_\n" for @nod;
Note that I have replaced last in your example with die, which will cause the evaluation block to be short-circuited.

My directory contains the following files:
try.pl try3.pl try0.pl try4.pl try0.txt try9.pl try6.pl try7.pl try8.pl try10.pl try11.pl text.txt try12.pl try13.pl try14.pl try15.pl p01.pl p02.pl p03.pl p04.pl p05.pl p09.pl p10.pl p11.pl p12.pl try2.pl try1.pl webrobot.pl links.txt algorithm.pl mainfile.txt
I want the code to short circuit as soon as it sees a file beginning with letter 'p'. And the output of the code is just as expected -
try.pl try3.pl try0.pl try4.pl try0.txt try9.pl try6.pl try7.pl try8.pl try10.pl try11.pl text.txt try12.pl try13.pl try14.pl try15.pl

Replies are listed 'Best First'.
Re: Re: File::Find exit
by sweetblood (Prior) on Oct 30, 2003 at 18:25 UTC
    This may well do it ... I'll get busy and try it out.