in reply to Error with doublequotes in map

Map has two formates map BLOCK LIST and map EXPR, LIST the difference is that comma. For some reason the quotes at the begging of the block trick perl into thinking it is an expression instead of a block.


___________
Eric Hodges

Replies are listed 'Best First'.
Re^2: Error with doublequotes in map
by Fletch (Bishop) on Feb 12, 2007 at 18:32 UTC

    Yup, it's thinking it's the LIST form with a hashref missing a trailing comma before the empty parens rather than BLOCK. If you parenthesize things it'll behave as well.

    $ perl -MO=Deparse,-p -Mstrict -Mwarnings -e 'map{("$_" => 1)} ();' use warnings; use strict 'refs'; map({("$_", 1);} ()); -e syntax OK

    Strange and surprising, yes. "Bug", hrmmm . . . I'd say more ambiguous corner of the grammar.

      Just for convenient reference:

      The standard ways to help Perl interpret expression (hash ref) vs. block correctly, is like this:

      map +{ "$_" => 1 }, @list # + => expression (hash ref) (+ comma) map {; "$_" => 1 } @list # ; => block (no comma)
      interestingly enough, if you leave the -p off of Deparse, it gives you
      map {"$_", 1;} ();
      which perl says is a syntax error.
Re^2: Error with doublequotes in map
by bennymack (Pilgrim) on Feb 12, 2007 at 18:33 UTC
    That makes a lot of sense! I'll pass it along. Thanks! Sorry for the Anonymous post. I didn't realize I wasn't logged in :|

      Also, use your perlbug program the next time you want to report a bug in perl. That goes to the people who actually deal with it.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

        Hmm, ok, but looks to me like OP didn't want to 'bug' the team with something that might be spurious, so raised it here first. Good on him I say.


        DWIM is Perl's answer to Gödel