http://www.perlmonks.org?node_id=222847


in reply to Complicated Hash Construction.

I always thought it was because in the first example perl knows that %hash is, well, a hash. In the second example perl has no way of knowing whether @hash is a hash or an array. It looks like an array (and the right-hand side is in list context) and the braces look like a syntax error.

There's no problem when you predeclare %hash because perl knows that @hash{ } is a hash slice and not an array.

Those more knowledgable about the Perl internals can comment on why this syntax can't be DWIM'd into the interpreter, but I suspect it will not be an issue in Perl 6.

Gary Blackburn
Trained Killer