Or you could do it like this:#!/opt/perl5/current/bin/perl chdir "/tmp/test"; $CONFIG = "some_string_with_no_filename_wildcards"; @files = glob("$CONFIG"); foreach $file (@files) { next unless -e $file; print "$file \n"; }
foreach $file ( grep {-e} @files ) { print "$file\n"; }
UPDATE: Actually, since the whole point of the "glob()" function (and the File::Glob module that implements it) is only to do file name expansions on strings that contain various kinds of regex-like wild-card matching directives, there is no point in using this function at all when a string does not contain any of these directives.
So, if your config file uses just a simple set of wild-card-type things (like "*" and "?"), it might be better to only invoke glob() when one of those things is present in the string. Otherwise, just just the "-e" operator on the string:
@files = ( $CONFIG =~ /[*?]/ ) ? glob( $CONFIG ) : ( -e $CONFIG ) ? ( +$CONFIG ) : ();
In reply to Re: glob pattern matching
by graff
in thread glob pattern matching
by KevinBr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |