my @check = grep { chomp $_; $_ } <DATA>;
Map should be used for this not grep. Consider the following.
use warnings; use strict; my @check = grep { chomp $_; $_ } <DATA>; print ">>@check<<" __DATA__ line1 0 line3
The output is:
>>line1 line3<<Grep looks at the value the block returns and if true it returns $_. Map is used to do something to each element and pass along the result from each.
To me it is clearer and simpler to do this:
my @check = <DATA>; chomp @check;
In reply to Re^3: Regular Expressions question
by Lotus1
in thread Regular Expressions question
by CJXJ220
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |