Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to use something like File::Find::Rule to get rid of some code that has the UNIX find command in it.
Working code:
sub AllInFilesystemResults { my ($class) = shift; my ($collectArchive) = shift; my @searchLocations; if ( $collectArchive =~ /^archive/ ) { @searchLocations = "/vol/$collectArchive/prod/*"; } else { @searchLocations = ( "/vol/archive*/prod/*/$collectArchive/*", "/vol/archive*/prod/system/archive/$collectArchive/*" ); } my %listOfFilesDatabase; foreach my $searchLocation (@searchLocations) { my @archivesInFilesystem = `find $searchLocation -type f 2> /dev/null | grep -v \"\/archive\/archive\/\"`; chomp @archivesInFilesystem; $searchLocation = qr/$searchLocation/; foreach my $locationFS (@archivesInFilesystem) { print "$locationFS\n"; utf8::decode($locationFS); $listOfFilesDatabase{$locationFS}++; } } return %listOfFilesDatabase; }
I would like @searchLocations to be regex that then gets searched through
if ( $collectArchive =~ /^archive/ ) { @searchLocations = "/vol/$collectArchive/prod/.+"; } else { @searchLocations = ( "/vol/archive\\d{2}/prod/.+/$collectArchive/.+", "/vol/archive\\d{2}/prod/system/archive/$collectArchive/.+" ); } my %listOfFilesDatabase; foreach my $searchLocation (@searchLocations) { $searchLocations = qw/$searchLocation/;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search directory recursive with regex
by Anonymous Monk on Mar 02, 2015 at 22:43 UTC | |
by Anonymous Monk on Mar 03, 2015 at 00:41 UTC |