dextius has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to understand two snippets of code, that have different behaviors that I do not immediately grasp.
Consider:
When ran, it returnsuse strict; use Data::Dumper; my @res = grep $_ split(",", "a,b,c,d,,f,,h"); print Dumper(\@res); my @res2 = grep { $_ } split(",", "a,b,c,d,,f,,h"); print Dumper(\@res2);
I understand the second example, as I am evaluating the "truth" of the elements I am iterating over. I do not understand the output of the first dump, when given just "$_". I did look at grep's perldoc, hoping for an ounce of clairvoyance, but to no avail.$VAR1 = [ 'a', 'c' ]; $VAR1 = [ 'a', 'b', 'c', 'd', 'f', 'h' ];
Back to
Seekers of Perl Wisdom