One of the goals of design with Perl variables was to make them visually distinguishable from embedded, reserved words, control flow words, etc. For someone unfamiliar with Perl, all the hints may look like linear noise. But for someone who owns Perl, the sigils, as they are called, make the code more understandable and understandable. As you already noticed, the sigil type in Perl5 changes depending on access to the underlying data. $ for scalar, @ for array and% for hash.
But there is an additional visual cue that $hash{key} refers to the scalar value stored in the hash. The $ symbol indicates a scalar, and the brackets {} indicate that we are indexing the hash (as an example). In the case of indexing into an array, $array[0] , for example: $ tells us that we are accessing the scalar value stored in the array, which is obvious in square brackets, at the index point in brackets. When we see @array[1, 2, 3] , we have a direct visual notification with @ that we grab a list of elements (subject to the context of the list) from the array (square brackets still tell us that we get them from the array ) This is a slice of an array. The hash slice will be @hash{qw/ this that the other/} . So again, what @ tells us to look for a list, and curly braces tell us that we get them from the hash. When we see @ or % without postfix brackets, we take the whole array or hash.
Signals become second nature fast.
Perl6 is a little different, and in a few days the user will use experienced Perl5 users.;)
There is a good Wikipedia article on the topic: Sigil (computer programming)
Besides visual guidance, sigils facilitate other things; dereferencing and interpolation, for example. Although more complex operators could be used for something like interpolation (and it is still necessary to disambiguate from time to time when the variable ends and adjoining word-characters continue), the goal was probably to simplify simple things by doing everything possible.
source share