in reply to Expression form of map or grep
FWIW, I agree with everything you said. However, I think you made a little error:
my @list = map( "$_ beads", @colors ), @grey_scale;
I think @list will not contain anything from @grey_scale, and would warn with something like "Useless use of private array in void context", because the assignment precedes the comma operator.
I do prefer the expression form with parentheses, though, partly because of an (I believe) obsolete reason which was that the block form would generate a new lexical space whereas the expression form wouldn't, so the expression form was apparently slightly more performant (on very large lists).
I also like making hashes with something like...
my %h = map +($_ => 1), @a;
...I guess because it seems the most generally correct, given the possible parsing bugs with Perl and map, but at the same time I can see that it's possibly confusing, especially given the "array in void context" comment above. :)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Expression form of map or grep
by AnomalousMonk (Archbishop) on Jul 12, 2020 at 01:56 UTC | |
Re^2: Expression form of map or grep
by Lady_Aleena (Priest) on Jul 12, 2020 at 12:19 UTC | |
by parv (Parson) on Jul 13, 2020 at 05:53 UTC | |
by Lady_Aleena (Priest) on Jul 13, 2020 at 10:39 UTC | |
by parv (Parson) on Jul 14, 2020 at 04:24 UTC | |
by Lady_Aleena (Priest) on Jul 14, 2020 at 12:19 UTC | |
|