in reply to Search directory recursive with regex

Although I agree that using Perl instead of calling find is probably better, I'm not sure if File::Find::Rule directly supports the operation you are looking for; you might have to build something that lists those paths yourself, but Path::Class or most likely Path::Tiny (see its children method) would probably be very helpful there.

Or, maybe in this case glob can help? (make sure to read its documentation, including File::Glob)

use File::Find::Rule; my @searchLocations = ( glob("/vol/archive[0-9][0-9]/prod/*/$collectArchive/*"), glob("/vol/archive[0-9][0-9]/prod/system/archive/$collectArchive/*") ); my @files = File::Find::Rule->file->in(@searchLocations);

By the way, as a side note, in your example regexes, .+ is probably better written as [^\/]+, because otherwise it may match any number of slashes as well.

Replies are listed 'Best First'.
Re^2: Search directory recursive with regex
by Anonymous Monk on Mar 03, 2015 at 00:41 UTC
    Two step solution is clever, saves work, here is the other way , direct translation
    #my @archivesInFilesystem = # `find $searchLocation -type f 2> /dev/null # | grep -v \"\/archive\/archive\/\"`; use File::Find::Rule qw/ find rule / my $keepers = sub { ## $_ is like $fullname ## my( $shortname, $path, $fullname ) = @_; ## return !!1 if $fullname =~ m{/archive/archive/}; # keeper return !!1 if m{/archive/archive/}; # keeper return !!0; # goner };; my @archivesInFilesystem = find( file => exec => $keepers, in => $searchLocation, );