my @emptyfiles = grep { /^\d+$/ } grep { -f } glob '*';
Let's look at this right to left. glob '*' returns a list of files, the same list you'd get if you use * as the argument to an ls or dir command, except it's just the file names, not the dates, sizes, etc that those commands also return. This list will be the input to the grep command.
my @emptyfiles = grep { /^\d+$/ } grep { -f } [ 1 temp.dat testdirecto +ry 10 resume.wd ]
grep { something } list returns the list that results by applying the something as a test. If it passes, it is included in the return. glob will return both file and directory names in its list. Applying the -f test will remove the directories. The middle grep returns a list also.
my @emptyfiles = grep { /^\d+$/ } [1 temp.dat 10 resume.wd ]
we can use another grep to further filter the list to just the files we want, those whose name consists of 1 or more digits, and nothing else.
my @emptyfiles = [1 10]
In reply to Re^3: create array of empty files and then match filenames
by GotToBTru
in thread create array of empty files and then match filenames
by angela2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |