[ale] Perl Problem

Eric Z. Ayers eric at compgen.com
Tue Oct 13 16:38:47 EDT 1998


Terry Lee Tucker writes:
 > Hi ALE:
 > 
 > The script below is a portion of a larger script. I'm having a problem
 > with the prune variable. I only want File::Find to look in the directory
 > I pass as an argument for files that match the pattern defined in the
 > "wanted" subroutine. According to my "Programming Perl" book by
 > O'Reilly, I should set the variable $File::Find::prune to true to
 > prevent find descending into subdirectories. When I set this variable, I
 > get nothing at all back. I know there are files that match this pattern
 > in the directory I am passing to find, but I get nothing back. If I set
 > the variable to zero, I get files from the /esc/rnd/prog directory, as
 > well as all the subdirectories below, which is not what I want. Am I
 > doing something wrong here?
Terry,

I don't have time to run a test, but it looks like you only want to
set the prune variable at the particular subdir to prune. Try:

 sub wanted()
 {
     if (-d)
     {
	 $File::Find::prune = 1;                 # don't descend subdirectors
     }
     else 
     {
	     (/^.*\.p$/) && push @files, $File::Find::name;
     }
 }

 > 
 > Any insight greatly appreciated :^>
 > 
 > #!/usr/bin/perl
 > 
 > use File::Find;
 > 
 > sub wanted()
 > {
 >     $File::Find::prune = 1;                 # don't descend subdirectors
 >     (/^.*\.p$/) && push @files, $File::Find::name;
 > }
 > 
 > find (\&wanted, "/$MNT/$DIR/prog/");
 > foreach $value (@files)
 > {
 >     print "$value\n";
 > }
 > 
 > -- 
 > Oakwood, GA 30566 USA
 > 770.965.9294
 > http://www.esc1.com
 > The Gates of hell shall NOT prevail...






More information about the Ale mailing list