Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Expression form of map or grep

by jcb (Parson)
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 pondering the Monastery: (3)
As of 2021-06-14 06:16 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (60 votes). Check out past polls.