{resending}

Hi Mike,

On Wed, 13 Dec 2017 11:28:55 +0000
Mike Martin <redt...@gmail.com> wrote:

> Hi
> I have the following code
> 
> use strict;
> use File::Find;
> my @vsbe;
> my $top='P:\PT-6\PT-60\PT-603\Shared\Data Store\Files Dump Folder';
> my $max_depth=9;
> my $cnt1=0;
> 
> find({wanted=>\&wanted1,preprocess=>\&preprocess1},$top) ;  
> 
> sub wanted1 {
> 
> if ($cnt1 <=1000){
> my $file = $File::Find::name;
> if (grep {/vsb$/} $file){
> push @vsbe, $file if $cnt1 <=1000 ;
> $cnt1++;
> print $cnt1,"\n" ;
> }
> else {return}
> 
> return if $cnt1 >=1000
> }
> return
> 
> }
> sub preprocess1 {
>     my $depth = $File::Find::dir =~ tr[\\][];
> #print 'depth',"\t",$depth,"\t",$File::Find::dir,"\n";
> return  @_ if $depth < $max_depth;
>     return grep { not -d } @_ if $depth == $max_depth;
>     return;
> }
> 
> Unfortunately the wanted function never returns, it (at best) stays stuck
> on print the last value of $cnt1 (1000)
> 
> Any ideas what is happening here

my guess based on reading your code is that File::Find continues to scan the
directory tree recursively and calling wanted1() for every file. This is one of
the design quirks of the F::F interface and I suggest looking at better
alternatives on CPAN, such as
http://www.shlomifish.org/open-source/projects/File-Find-Object/ which I
maintain. See https://shlomif-tech.livejournal.com/29315.html for an article I
wrote about some other philosophical limitations of F::F that I solve (one of
them is similar to your use case).

Regards,

        Shlomi

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to