Hi Mike,
On Wed, 13 Dec 2017 11:28:55 +0000
Mike Martin <[email protected]> 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
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
http://is.gd/i5eMQd - Emma Watson’s Interview for a Software Dev Job
In the beginning the Universe was created. This has made a lot of people very
angry and been widely regarded as a bad move.
— https://en.wikiquote.org/wiki/The_Hitchhiker's_Guide_to_the_Galaxy
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/