On Wed, 2017-12-13 at 11:28 +0000, Mike Martin 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){
grep works on lists so you don't need grep there: if ( $file =~ /vsb$/ ) { > 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 The wanted function does return, but it does not return to your process. It is called inside a loop in the File::Find code and when it returns the loop continues until all the files are found. John -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/