If you want to handle glob patterns, use the glob
operator to expand them. Then test all the paths, store the results in a hash, and return the hash.
sub FileExists {
my @param = map glob($_) => @{ shift @_ };
my %exists;
foreach my $file (@param) {
print $file, "\n";
$exists{$file} = -e $file;
}
wantarray ? %exists : \%exists;
}
Then say you use it as in
use Data::Dumper;
my @arr = ('/tmp/test/test.*.con', '/usr/bin/a.txt');
my $result = FileExists(\@arr);
$Data::Dumper::Indent = $Data::Dumper::Terse = 1;
print Dumper $result;
Sample run:
$ ls /tmp/test
test.1.con test.2.con test.3.con
$ ./prog.pl
/tmp/test/test.1.con
/tmp/test/test.2.con
/tmp/test/test.3.con
/usr/bin/a.txt
{
'/tmp/test/test.3.con' => 1,
'/tmp/test/test.1.con' => 1,
'/usr/bin/a.txt' => undef,
'/tmp/test/test.2.con' => 1
}