Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Mysterious "syntax error"

by bart (Canon)
on Nov 30, 2004 at 15:52 UTC ( [id://411218]=note: print w/replies, xml ) Need Help??


in reply to Mysterious "syntax error"

It's the classical block vs. anonymous hash mixup. The syntax is ambiguous, so perl hash to make a guess. Perl wrongly assumes you want an anonymous hash here, thus it's assuming the map EXPR, LIST syntax, so it expects to see a comma. Which isn't there. At that time, perl has gone too far in parsing the source, and it can't backtrack any more, and it throws in the towel.

Typical solutions are to prepend a "+" if you indeed want an anonymous hash, or put a ";" right after the opening brace, if you want a block. That way, you disambiguate the syntax at an early enough stage.

  • anonymous hash: +{ 'A' => $_ }
  • block: {; 'A' => $_ }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-03-29 08:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found