One of the design goals with Perl's variables was to make them visually distinguishable from builtins, reserved words, control flow words, and so on. To someone unfamiliar with Perl, all the clues may look like line noise. But to someone proficient with Perl, the "sigils", as they're called, make code more readable and more understandable. As you already observed, the type of sigil in Perl5 changes depending on the underlying data being accessed. $ for scalar, @ for array, and % for hash.
But there is the additional visual cue that $hash{key}
is referring to the scalar value held in the hash. The $
sigil indicates scalar, and the {}
brackets indicate that we're indexing into a hash (just as an example). In the case of indexing into an array, $array[0]
, for example: The $
tells us we're accessing the scalar value held in the array, made obvious by the square brackets, at the index point within the brackets. When we see @array[1, 2, 3]
, we have an immediate visual notice by way of the @
that we're grabbing a list of elements (assuming a list context) from an array (the square brackets still tell us we're getting them from an array). That's an array slice. A hash slice would be @hash{qw/ this that the other/}
. So once again that @
tells us to be looking for a list, and the curly brackets tell us we're getting them from a hash. When we see a @
or a %
without postfix brackets, we're taking the entire array or hash.
The cues become second nature quickly.
Perl6 is a little different, and will take proficient Perl5 users a few days to get used to. ;)
There's a good Wikipedia article on the subject here: Sigil (Computer Programming)
Aside from the visual guide, the sigils make other things easier too; dereferencing and interpolation, for example. While more elaborate operators could have been used for something like interpolation (and are still necessary occasionally to disambiguate where a variable ends and adjoining word characters continue), the goal was probably to keep simple things easy, while making hard things possible.