in reply to glob pattern matching
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 ) : ();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: glob pattern matching
by KevinBr (Acolyte) on Jan 14, 2010 at 15:43 UTC |