in reply to Is { } an empty block or a bug in perl?

Would {}{} be
1) a block followed by a hash constructor,
2) a hash constructor followed by a block,
3) a hash constructor followed by a hash constructor, or
4) a block followed by a block?

They are not equivalent. At least, they are not equivalent if found at the end of a sub. The syntax error forces the user to disambiguate.

Replies are listed 'Best First'.
Re^2: Is { } an empty block or a bug in perl?
by Joost (Canon) on Jul 06, 2005 at 19:32 UTC
    It could only be 1 or 4. An empty hashref that's not at the end of a block, file or list or in a complex expression should be terminated by a semi-colon (like any other (sub)expression). A block is terminated by its closing brace.

    My main objection is that it's silly to have a discrepancy between the current behaviour:

    {} # hashref
    and the proposed:
    {}{} # two blocks...
    So it's best to keep the current behaviour, ie. syntax error. I must say the current syntax error is actually pretty accurate too, so it won't be too hard to find the problem either.