in reply to Puzzling syntax error

Changing the code to:

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

also takes care of the error, although it does not answer your original question :)

--MidLifeXis

Replies are listed 'Best First'.
Re^2: Puzzling syntax error
by FunkyMonk (Bishop) on Aug 15, 2008 at 17:43 UTC
    As does the semi-colon trick
    my %hash = map {; "$_" => 1 } qw(a b c);

    Update:

    I thought I'd better explain this idiom since Lawliet /msg'ed me about it.

    Braces in perl are used for hashrefs and for blocks and sometimes perl has to "guess" at the intended meaning. Sometimes (as in this case), perl gets it wrong. The addition of a semicolon convinces perl it's a block, not a hashref.

    At least that's how I understand it :-)


    Unless I state otherwise, all my code runs with strict and warnings