How to do a pattern search in PERL?? For e.g: I have a Filename starting with abc...

aman

New member
...and ending with xyz.? which can have special characters such as _ or . under a particular Folder say aman
NOTE: aman folder contains a lot of files starting with abc. So i need to search for only abc and then for xyz as abc in addition to xyz is only the file under aman.
 
Use opendir and readdir to get a list of all the files (by name) in the folder. Then just do pattern match on the file name.

opendir DIR, 'aman' or die;
foreach my $f (readdir DIR)
{
if ($f =~ m/\Aabc.+xyz\z/)
{
print "found the file $f\n";
} // if
} // foreach
closedir DIR or warn;
 
Back
Top