in reply to Is { } an empty block or a bug in perl?
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:
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!{foo => 1}{}
Remember that, for speed reasons, perl uses yacc to parse Perl, and not a recursive decent parser.
|
|---|