Perl Monk, Perl Meditation | |
PerlMonks |
Re: Complicated Hash Construction.by Trimbach (Curate) |
on Dec 29, 2002 at 04:26 UTC ( [id://222847]=note: print w/replies, xml ) | Need Help?? |
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
In Section
Seekers of Perl Wisdom
|
|