Dear Monks,
I am writing a script that can take the search pattern as an argument and list all the files that match that pattern in a specified directory.
The below script works fine as long as I provide the search pattern as words or numbers.
use strict; my $wildcard = $ARGV[0]; print "wildcard is $wildcard\n"; my $filespath = '/path/to/files/'; opendir DIR, $filespath or die "Couldn't open $filespath: $!\n"; # Sort by asc order (time) # (The commented line below sorts all the files that end with ".cgi" #my @dirfiles = sort { -M $filespath.$a <=> -M $filespath.$b } grep /\ +.cgi$/, readdir DIR; my @dirfiles = sort { -M $filespath.$a <=> -M $filespath.$b } grep /$w +ildcard/, readdir DIR; foreach (@dirfiles){ print "$filespath$_\n" }
How do I make it work for patterns such as "a*sample*.cgi" (the string to match is within the quotes)?
Thanks, Vgn
In reply to Wildcard search in a directory by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |