The code:
my @hash{@keyarray} = @valuearray;Should be understood as:
my($hash{$keyarray[0]}, $hash{$keyarray[1]}, ...) = @valuearray;Once this is understood, it should be easier to see why Perl considers the expression to be a syntax error. Perl does not know what my($hash{$key}); means. The exact error is `Can't declare hash slice in "my" at ...'
For an interesting comparison, consider the following similar-looking code:
local @hash{@keyarray} = @valuearray;This code actually works, because local($hash{$key}); is perfectly valid and means 'override the value of $hash{$key} until this block completes'.
In reply to Re: Complicated Hash Construction.
by MarkM
in thread Complicated Hash Construction.
by coolmichael
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |