http://qs321.pair.com?node_id=11119196


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);