Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.9k stars 540 forks source link

File::Find Module (preprocess and postprocess) #4092

Closed p5pRT closed 19 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#7127 (status was 'resolved')

Searchable as RT7127$

p5pRT commented 23 years ago

From njancesk@summithq.com

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!

Perl Info ``` Flags: category=library severity=medium Site configuration information for perl v5.6.1: Configured by njancesk at Mon May 14 11:17:01 EDT 2001. Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration: Platform: osname=solaris, osvers=2.6, archname=sun4-solaris uname='sunos detroit 5.6 generic_105181-21 sun4u sparc sunw,ultra-80 ' config_args='' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags =' -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O', cppflags='' ccversion='', gccversion='', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, usemymalloc=y, prototype=define Linker and Libraries: ld='cc', ldflags =' ' libpth=/usr/lib /usr/ccs/lib libs=-lsocket -lnsl -ldl -lm -lc perllibs=-lsocket -lnsl -ldl -lm -lc libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' cccdlflags='-KPIC', lddlflags='-G' Locally applied patches: @INC for perl v5.6.1: /u/njancesk/progs/perl/lib/5.6.1/sun4-solaris /u/njancesk/progs/perl/lib/5.6.1 /u/njancesk/progs/perl/lib/site_perl/5.6.1/sun4-solaris /u/njancesk/progs/perl/lib/site_perl/5.6.1 /u/njancesk/progs/perl/lib/site_perl . Environment for perl v5.6.1: HOME=/u/njancesk LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH=/usr/openwin/lib:/usr/dt/lib:/apps/pkgs/sybase/lib:/apps/pkgs/oracle/lib:/apps/pkgs/orbix/lib LOGDIR (unset) PATH=/u/njancesk/progs/BerkeleyDB.3.2/bin:/u/njancesk/progs/mysql/bin:/u/njancesk/progs/perl/bin:/apps/pkgs/InstallShield-4.01:/apps/pkgs/jdk-1.2.2.05/bin:/u/njancesk/bin:/u/njancesk:/apps/utils/bin:/bin:/usr/bin:/usr/bin/X11:/global/utils/bin:/apps/bin:.:/usr/openwin/bin:/usr/ccs/bin:/usr/ucb:/usr/sbin:/apps/utils/dbbin:/apps/utils/dt/bin:/usr/dt/bin:/apps/bin:/usr/bin:/bin:/u/deliv/bin:/apps/pkgs/flexlm-6.0/flexlm/v6.0/sun4_u5:/u/njancesk/bin:/u/njancesk/script PERL_BADLANG (unset) SHELL=/bin/ksh ```
p5pRT commented 19 years ago

From @smpeters

[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.

p5pRT commented 19 years ago

@smpeters - Status changed from 'open' to 'resolved'