Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

find2perl

45 views
Skip to first unread message

Oryann9

unread,
Jan 7, 2008, 10:22:44 PM1/7/08
to Perl List

In find2perl, prune is set to 1 for true as in DO NOT desend dirs? From the man page "-prune"
Do not descend into the directory currently matched.

Likewise for File::Find prune set to 1?

$ find2perl /dirname -size +4092k -ls -prune

thank you


____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping

Randal L. Schwartz

unread,
Jan 7, 2008, 11:24:35 PM1/7/08
to begi...@perl.org
>>>>> "oryann9" == oryann9 <ory...@yahoo.com> writes:

oryann9> $ find2perl /dirname -size +4092k -ls -prune

Since -prune is *after* the condition of -size, you're setting
prune only for VERY VERY LARGE directories. Is that your
intent?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Oryann9

unread,
Jan 7, 2008, 11:52:25 PM1/7/08
to begi...@perl.org
oryann9> $ find2perl /dirname -size +4092k -ls -prune

Since -prune is *after* the condition of -size, you're setting
prune only for VERY VERY LARGE directories. Is that your
intent?

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


No, but good point. My intent was to determine when -prune was set on the CLI what the De-parsed code told me, 1==true, 0==false because when I run this code below prune = 0 is not working, its descending down "/".


use strict ;
use warnings ;
use File::Find ;
use File::Find::Closures qw(find_by_min_size) ;
<snip>

find_me ( $fs, 0 );

<snip>

sub find_me {
use Data::Dumper;
my $fs = shift;
print "FS from sub\t$fs\n";
print Dumper(local $File::Find::prune = shift); ##-- localize prune to just this block --##
use constant MAX_SIZE => (25*1024*1024) ;
use constant DIVISOR => (1024) ;
my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ;
File::Find::find ( { wanted => $wanted, }, $fs ) ;

@large_files = $list->() ;

@sorted_large_files =
sort { -s $b <=> -s $a }
@large_files ;

} ##-- End sub --##


<snip>


thx for the reply!

____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Randal L. Schwartz

unread,
Jan 8, 2008, 12:25:47 AM1/8/08
to begi...@perl.org
>>>>> "oryann9" == oryann9 <ory...@yahoo.com> writes:

oryann9> No, but good point. My intent was to determine when -prune was set on
oryann9> the CLI what the De-parsed code told me, 1==true, 0==false because
oryann9> when I run this code below prune = 0 is not working, its descending
oryann9> down "/".

You're misusing it. Set it within the wanted() routine when you're looking at
a directory that you don't want to descend. It'll be cleared to 0 before
calling wanted(), so setting it before calling find() is completely useless.

Oryann9

unread,
Jan 9, 2008, 3:21:45 PM1/9/08
to begi...@perl.org

oryann9> No, but good point. My intent was to determine when -prune was
set on
oryann9> the CLI what the De-parsed code told me, 1==true, 0==false
because
oryann9> when I run this code below prune = 0 is not working, its
descending
oryann9> down "/".

You're misusing it. Set it within the wanted() routine when you're
looking at
a directory that you don't want to descend. It'll be cleared to 0
before
calling wanted(), so setting it before calling find() is completely
useless.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.

-

__OUTPUT__

main::(find_hog:47): if ( $fs eq "/" ) { # only if the root directory
DB<1> print $fs
/
DB<2> n
main::(find_hog:48): find_me ( $fs, 0 );
DB<2> n

print caller find_me
main::(find_hog:61): my ( @sorted_large_files, @large_files ) ;
DB<2>
main::(find_hog:80): if (@sorted_large_files) {
DB<2> print caller find_me
invalid top directory at /opt/perl/lib/5.8.2/File/Find.pm line 568, <> line 1.

DB<3> print $fs
/
DB<4> n
main::(find_hog:81): my %meta ;
DB<4> n
main::(find_hog:82): for my $file (@sorted_large_files) {
DB<4> n
main::(find_hog:83): $meta{$file} = {
main::(find_hog:84): 'uid' => (stat($file))[4],
main::(find_hog:85): 'gid' => (stat($file))[5],
main::(find_hog:86): 'sz' => (stat($file))[7],
main::(find_hog:87): 'mod' => (stat($file))[9],
DB<4> print $file
/data/data01/recovery/archives/dubhdv04/2007-11-15,11:21
DB<5>

/data/... should not be appearing if prune set to false, or 0.

__CODE__

Is this what you mean on line 9? I tried and it does not seem to work, meaning it still descending.

1 sub find_me {
2 use Data::Dumper;
3 my $fs = shift;
4 #local $File::Find::prune = shift; ##-- localize prune to just this block --##
5 #my @directory = ($fs) ;
6 use constant MAX_SIZE => (25*1024*1024) ;
7 use constant DIVISOR => (1024) ;
8 my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ;
9 File::Find::find ( { wanted => $wanted, prune => $File::Find::prune = shift}, $fs ) ;
10 @large_files = $list->() ;
11
12 @sorted_large_files =
13 sort { -s $b <=> -s $a }
14 @large_files ;
15
16 } ##-- End sub --##

____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs

Tom Phoenix

unread,
Jan 9, 2008, 5:34:46 PM1/9/08
to oryann9, begi...@perl.org
On Jan 9, 2008 12:21 PM, oryann9 <ory...@yahoo.com> quoted Randal Schwartz:

> > You're misusing it. Set it within the wanted() routine when you're

> Is this what you mean on line 9? I tried and it does not seem to work,


> meaning it still descending.
>
> 1 sub find_me {
> 2 use Data::Dumper;
> 3 my $fs = shift;
> 4 #local $File::Find::prune = shift; ##-- localize prune to just this block --##
> 5 #my @directory = ($fs) ;
> 6 use constant MAX_SIZE => (25*1024*1024) ;
> 7 use constant DIVISOR => (1024) ;
> 8 my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ;
> 9 File::Find::find ( { wanted => $wanted, prune => $File::Find::prune = shift}, $fs ) ;
> 10 @large_files = $list->() ;
> 11
> 12 @sorted_large_files =
> 13 sort { -s $b <=> -s $a }
> 14 @large_files ;
> 15
> 16 } ##-- End sub --##

That's not within your wanted() routine.

File::Find will call your wanted() code many times. Your code will
normally leave prune alone. At some point, your code will find itself
dealing with a directory into which you don't want to search, so your
code will set prune to a true value; this will cause File::Find to say
to itself, "Ho ho! You don't want to go deeper than here! Your wish is
my command!" It will consider that directory to be complete, and go on
to the next, thereby pruning the search tree.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

Oryann9

unread,
Jan 11, 2008, 2:32:11 PM1/11/08
to begi...@perl.org
>You're misusing it. Set it within the wanted() routine when you're
>looking at
>a directory that you don't want to descend. It'll be cleared to 0
>before
>calling wanted(), so setting it before calling find() is completely
>useless.

>--
>Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
>0095
><mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
>Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.

-

Is this what you mean on line 9? I tried and it does not seem to work,
meaning it still descending.

1 sub find_me {
2 use Data::Dumper;
3 my $fs = shift;
4 #local $File::Find::prune = shift; ##-- localize prune
to just this block --##
5 #my @directory = ($fs) ;
6 use constant MAX_SIZE => (25*1024*1024) ;
7 use constant DIVISOR => (1024) ;
8 my ( $wanted, $list ) = find_by_min_size ( MAX_SIZE ) ;
9 File::Find::find ( { wanted => $wanted, prune =>
$File::Find::prune = shift}, $fs ) ;
10 @large_files = $list->() ;
11
12 @sorted_large_files =
13 sort { -s $b <=> -s $a }
14 @large_files ;
15
16 } ##-- End sub --##

0 new messages