in reply to File::Find exit

Simplest option will be to use the preprocess argument e.g
find({ wanted => \&foo, preprocess => sub { grep !/^d/i, @_ }, }, '/somedir');
See. the File::Find docs for more info.

Update: as tye has pointed out, the above doesn't really answer your question. Since File::Find wasn't designed to allow stopping mid-process, File::Find::Rule is probably a better option e.g

use File::Find::Rule; my $seen = 1; my @files = find( file => exec => sub { $seen = 0 if /^d/i; $seen }, in => '/somedir' );
Or if you really want to stop iterating once you've seen the first file beginning with a 'd'
my @files; my $rule = rule(file => start => '/somedir'); while(my $file = $rule->match) { last if $file =~ /^d/i; push @files => $file; }
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: File::Find exit
by pg (Canon) on Oct 29, 2003 at 17:26 UTC

    Personally I think that he needs to explain more, as what he meant by that "before" in his last section. Without a clear understanding of that, no way we can give a correct answer. Well one answer might happen to be the right answer, but that's not the scientific way.

    For example, he might mean all the files start with [a-cA-C]. But this fails to consider chars other than alpha's.

    He might mean sort all filenames in dictionary order, and only grab those comes before d|D. If this is the case, one have to be caeful that all UPPER case chars come before lower case 'd' if order by ascii ord(). In this case, below code might be something he wants:

    use File::Find; use Data::Dumper; use strict; use warnings; my @nod; print ord('d'), "\n"; print ord('D'), "\n"; find({ wanted => \&foo }, '.'); print Dumper(\@nod); sub foo {push @nod, $_ if (lc($_) lt "d")}