use strict;
use warnings;
use File::Next;
my $find_this = sub {
my ($starting_points, $target) = @_;
my $ref_sub = File::Next::files( "$starting_points" );
while ( my @files = $ref_sub->() ) {
return @files if $files[1] =~ $target;
}
};
my @files = &$find_this( "/tmp/dir1", "file3.txt" );
print "@files\n";
####
$ ./file_next.pl
/tmp/dir1/dir3 file3.txt /tmp/dir1/dir3/file3.txt
####
For the three iterators, the \%options are optional.
files( [ \%options, ] @starting_points )])
####
sub findfile {
my ($target, $starting_points ) = @_;
my $file = File::Next::files( { file_filter => sub { /$target$/ } }, "$starting_points" );
while ( my @files = $file->() ) {
return $files[0], $files[1], $files[2]; #directory, filename, full path and name
}
}