Re: Find::Perl find not returning

2017-12-13 Thread John W. Krahn
On Wed, 2017-12-13 at 11:28 +, 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=>\,preprocess=>\},$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/




Re: Find::Perl find not returning

2017-12-13 Thread Shlomi Fish
{resending}

Hi Mike,

On Wed, 13 Dec 2017 11:28:55 +
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=>\,preprocess=>\},$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/




Re: Find::Perl find not returning

2017-12-13 Thread Shlomi Fish
Hi Mike,

On Wed, 13 Dec 2017 11:28:55 +
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=>\,preprocess=>\},$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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Find::Perl find not returning

2017-12-13 Thread Mike Martin
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=>\,preprocess=>\},$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