Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: map problem

by moritz (Cardinal)
on Mar 09, 2012 at 10:57 UTC ( #958676=note: print w/ replies, xml ) Need Help??

in reply to map problem

This is another instance of the problem that a pair of curlies can stand for an anonymous subroutine or a hash reference. You can disambiguate with a semicolon in the block:

my %y = map {; "prefix_$_" => 1 } qw(a b c);

It's more of a design limitation than a bug in perl or in you :-)

Comment on Re: map problem
Download Code
Replies are listed 'Best First'.
Re^2: map problem
by morgon (Deacon) on Mar 09, 2012 at 11:01 UTC
    Ok, but why is it neccessary only in the second case?

      The decision to parse an opening curly bracket as a block or a hash ref is really just a heuristic. When the parser sees a string quote, it decides in favor of the hash ref, whereas a variable makes it assume a block.

      Or put differently, the parser cheats as hell, and sometimes that backfires. But not always.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2015-11-29 15:56 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls