Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Expression form of map or grep

by jcb (Vicar)
on Jul 12, 2020 at 03:37 UTC ( #11119196=note: print w/replies, xml ) Need Help??

in reply to Expression form of map or grep

As tobyink mentions, the expression forms can be slightly faster because they avoid entering/leaving a block, but the block forms offer just that: a block where additional lexicals can be defined. In more complex uses, the block form can therefore be needed.

The block forms are also easier to read when using map to expand an array into key-value pairs to load a hash — fat comma will not parse correctly without extra parentheses and I get confused about whether those parentheses will define the entire argument list or just the leading expression.

my %index = map { $_->key => $_ } @objects;

is easier for me to read than:

my %index = map (($_->key => $_), @objects);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119196]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2020-11-01 01:32 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (291 votes). Check out past polls.