Wouldn't it be illegal Perl code if it was anything but a $ in that place?
The reason the sigil is required is that it designates what you are retrieving from the container. So for instance, @array[] is suggesting that you are accessing an array and expecting an array from it. This is called an array slice. Similarly, @hash{} is a hash slice, and you are expecting more than one value from the hash. To retrieve multiple values, you have to provide multiple indexes/keys. So for an array: my @values = @array[1, 3, 5, 7], and for a hash: my @values = @hash{qw/a b c/};
In reply to Re: Why do you need $ when accessing array and hash elements in Perl?
by lostjimmy
in thread Reaped: Why do you need $ when accessing array and hash elements in Perl?
by NodeReaper
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |