1. I'm getting a warning about using @fileList in the sub-subroutine. I know that's bad form, but I couldn't figure out a better way to do this. Is there a better way?Use an anonymous sub instead of a nested sub (see. tilly's Re (tilly) 9: Why are closures cool? for more info on why they aren't always safe) e.g
sub getFileList { my @fileList = (); # list for matching files my $findFilter = sub { if ( /\.hhc$/ ) { # only push matching filenames my $curDir = cwd; my $fileName = $curDir . $_; push @fileList, $fileName; } return; }; find($findFilter, "."); # populates the list return @fileList; }
2. I'd like to extract paths relative to the starting directory. I tried to do this by passing cwd from getFileList to findFilter. However, whenever I pass parameters to fileFilter, it seems to lose the file from $_. Is there a way to pass arguments into fileFilter?You may very well just want to use $File::Find::name instead of constructing it yourself.
As always TIMTOWTDI
See. File::Find::Rule for more info.use File::Find::Rule; my @files = find( file => name => '*.hhc', dir => '.' );
_________
broquaint
In reply to Re: Using File::Find to Create a List of Files
by broquaint
in thread Using File::Find to Create a List of Files
by svsingh
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |