A small point, but perhaps worth mentioning... You've got 3 grep's and a map. Each one of these things essentially does a foreach on its input. With Perl grep you can put anything that you want to into the grep - whatever that is, it only has to return a true or a false value. If true the input element from the right passes to the left. So all 3 grep's could be combined into one as shown below. Does the same thing but will run a bit faster - although usually of no importance. It is also possible to combine all this into a single map although I don't think that I'd do it in this case because it reads to me as less clear...this is just an example of "how" should the desire arise... The important part here is the return value. Returning () from a map is different than returning undef. Undef is a value. () means "nothing is returned".
I guess as a side point, I like lining up logical conditions because human beings are "programmed" by instinct to process information better from top to bottom better than left to right and certainly better than diagonally. So when things don't fit nicely on one printed line, I do it like below.
my @files2 = grep { $_ ne "file1"
and $_ ne "file2"
and -f "$dir2/$_" }map { lc }readdir(DIR2);
my @files = map { lc;
( $_ ne "file1"
and $_ ne "file2"
and -f "$dir2/$_" ) ? $_ :() }readdir(DIR2);
|