in reply to Question: File name pattern match using Grep function
# Finds a file called 1txt (WHY)
Because "\.txt" becomes just '.txt', which when it is reinterpolated here:
my @files =grep(/$file_mask$/,readdir(DIR));
Is taken to mean 'any char' followed by 'txt$'. To avoid the problem, use
my @files =grep(/\Q$file_mask\E$/,readdir(DIR));
To prevent characters within $file_mask being treated as meta characters.
|
|---|