After all, you give it well written code and it complains about a syntax error.
"Well written code"? It's a syntax error, so it isn't well written!

We all know that { } is overloaded in Perl. It could be the start of a block, and it could be the start of a hashref - and often, context won't tell perl what to expect. So Perl has to guess based on what's inside the braces - but there's nothing inside to help perl, so it guesses "hashref".

And it's not easy to fix - not without a lot of backtracking. What do you think:

{foo => 1}{}
should parse as? It's currently a syntax error (because perl thinks the first { } construct is a hashref), but perl could parse it as two blocks as well!

Remember that, for speed reasons, perl uses yacc to parse Perl, and not a recursive decent parser.


In reply to Re: Is { } an empty block or a bug in perl? by Anonymous Monk
in thread Is { } an empty block or a bug in perl? by cog

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.