Re: installed modules - faq question 3.4 What am I doing wrong?



randp@xxxxxxx wrote:
use File::Find;
my @files;

find sub { push @files, $File::Find::name if -f _ && /\.pm$/ },
@INC;

print join "\n", @files;
-------------------------------------------------------

I think the above code will go through each directory listed in @INC
and all its subdirectories and list all the files ending with ".pm".
Why is it not doing this?

It is missing a whole bunch of files with ".pm".  Am I doing something
wrong?

Yes. The file test operators require a *valid* filehandle or a file name. This should work (untested):


find sub { push @files, $File::Find::name if -f && /\.pm$/ }, @INC;


Or if you want to use more then one file test you could stat() or lstat() the file first:


find sub { stat; push @files, $File::Find::name if -f _ && -s _ && /\.pm$/ }, @INC;



John
--
use Perl;
program
fulfillment
.



Relevant Pages

  • rm all *.orig files in subdirectories?
    ... It only removes the files ending in *.orig from the top directory. ... I thought -r was the recursive option to do subdirectories also? ...
    (linux.redhat)
  • rm all *.orig files in subdirectories?
    ... It only removes the files ending in *.orig from the top directory. ... I thought -r was the recursive option to do subdirectories also? ...
    (linux.redhat)
  • Re: rename *-ch03.htm to ch03-*.htm?
    ... Perl 5 by Example Variables-ch03.htm rename to ... are files ending in htm ... A sentence like this might piss of a lot of people. ... Perl help, tutorials, and examples: http://johnbokma.com/perl/ ...
    (comp.lang.perl.misc)