in reply to Re^2: 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 '*';

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]
But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Replies are listed 'Best First'.
Re^4: create array of empty files and then match filenames
by angela2 (Sexton) on Jan 07, 2016 at 16:59 UTC
    Oh thanks! I read loads of stuff on perldoc and still couldn't work out I had to read it from right to left to decrypt it. Thank you so much, great explanation.

      For reference, that -f thing is documented at -X. (It's hard to search for, is why I'm linking.)

      $_="msh210";$"=$\;@_=@{[split//,uc]}[2,0];$_="@_$\1";$\=$/;++$_[0]for$...1;print lc substr crypt($_,"@_"),1,6