perl -e '{};{}' # works
perl -e '{1}{}' # works
perl -e '{}{1}' # works
perl -e '{}{}' # doesn't work
It should, shouldn't it? After all, it's just two empty blocks...
No, they're not.
To perl, those are two hashrefs.
In fact, to perl, there are two hashrefs in the first example and one in each of the following two.
If you don't believe me, try it yourself:perl -MO=Terse -e '{};{}'
As for fixing that, it seems very unlikely it will ever be...
And thus ended an interesting conversation with the #p5p folks:
<rgs> cog: does this come from generated code ?
<cog> rgs, er... no...
<cog> and don't you dare asking me how I came up with it
* cog goes back to his secret experiments
<rgs> damn.
-sam
Re:Non-Deterministic Parsing
davebaker on 2005-07-05T18:21:10
Good point -- I think you're supposed to put a plus-sign (unary operator) in front of the first brace if you want to be sure the compiler sees it as an anonymous hash: +{...}, or put a semi-colon (representing an empty statement) at the beginning of the block if you want to be sure the compiler sees it as a block: {; ...}. (Source: merlyn's Learning Perl Objects, References & Modules book, p. 40.)