Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Mysterious "syntax error"

by bart (Canon)
on Nov 30, 2004 at 15:52 UTC ( #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? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2022-05-21 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (76 votes). Check out past polls.

    Notices?