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' ];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Confusing grep behavior
by FunkyMonk (Chancellor) on Dec 04, 2007 at 21:16 UTC | |
by dextius (Monk) on Dec 04, 2007 at 23:32 UTC | |
Re: Confusing grep behavior
by grep (Monsignor) on Dec 04, 2007 at 21:19 UTC | |
by dextius (Monk) on Dec 04, 2007 at 23:33 UTC | |
by perrin (Chancellor) on Dec 04, 2007 at 23:52 UTC | |
by dextius (Monk) on Dec 05, 2007 at 00:44 UTC | |
by grep (Monsignor) on Dec 05, 2007 at 00:44 UTC | |
Re: Confusing grep behavior
by lodin (Hermit) on Dec 04, 2007 at 21:17 UTC | |
Re: Confusing grep behavior
by cdarke (Prior) on Dec 05, 2007 at 10:25 UTC |
Back to
Seekers of Perl Wisdom