Why it's a syntax error:
my @hash{1..4}=(1..4);
but not this one:
my %hash;
@hash{1..4}=(1..4);
the 1st example is of a lexically scoped 'my' + a hash slice which pre-supposes that one can declare a hash in the manner of a slice which is not valid syntax. your 2nd example is appropriate, declaring the hash first, assuming that you're use'ing strict + warnings;
my requires a variable or a list of variable in parens as argument.
@hash{1..4}
is neither of those, so
my @hash{1..4}
is a syntax error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With