in reply to Re: create array of empty files and then match filenames
in thread create array of empty files and then match filenames
my @emptyfiles = grep { /\d/ } grep { -f } glob '*';
Why two greps?
I don't think it makes a big difference for a small set of files, but this solution runs through two loops (implicitly in grep) where one loop is sufficient:
my @files = grep { -f && /\d/ } glob '*';Also, -f hides a system call (stat), which is quite expensive. Swapping the order avoids the system call for all directory entires whose names do not match the regular expression:
my @files = grep { /\d/ && -f } glob '*';Or, if you want to keep the two greps:
my @files = grep { -f } grep { /\d/ } glob '*';Alexander
|
|---|