develooper Front page | perl.perl5.porters | Postings from December 2004

[perl #7127] File::Find Module (preprocess and postprocess)

From:
Steve Peters via RT
Date:
December 31, 2004 11:42
Subject:
[perl #7127] File::Find Module (preprocess and postprocess)
Message ID:
rt-3.0.11-7127-104935.11.7029078941212@perl.org
> [njancesk@summithq.com - Mon Jun 18 02:33:43 2001]:
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> Using the Perl module File::Find (v 5.6.1), I noticed that when
> the 'follow' is set the 'preprocess' and 'postprocess' subroutine
> is never run.
> 
> Here is the code to reproduce the problem:
> 
> #!/usr/bin/perl
> @ARGV = qw (.) unless @ARGV;
> use File::Find;
> 
> sub doit {
> print "Files in $File::Find::dir: @_\n";
> return @_;
> }
> 
> find {
> 	wanted => sub {},
> 	preprocess => \&doit,
> 	follow => 1
> 	}, @ARGV;
> 
> __END__
> 
> 
> This should print the contents of each directory,
> but nothing happens.
> 
> I use preprocess to ignore specific directory names and this is
> when this becomes a serious problem.
> 
> Great module otherwise!
> 
> 

From the File::Find documentation....

preprocess

    The value should be a code reference. This code reference is used to
preprocess the current directory. The name of the currently processed
directory is in $File::Find::dir. Your preprocessing function is called
after readdir(), but before the loop that calls the wanted() function.
It is called with a list of strings (actually file/directory names) and
is expected to return a list of strings. The code can be used to sort
the file/directory names alphabetically, numerically, or to filter out
directory entries based on their name alone. When follow or follow_fast
are in effect, preprocess is a no-op.


The subroutine pointed to by preprocess is not called because you also
have "follow => 1" as noted in the documentation.  This is not a bug.




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About