Once upon a time, when I started using arrays in Perl, I found myself wanting to write things like
my $house = @street. It took me a while to understand that I should use a scalar,
$street, instead of an array slice,
@street. I felt that as I was dealing with an array, I should use the
I've noticed others making the same mistake, and I've had trouble helping others learn the difference between
$ in this context. In English, we might translate
my $house = $street to my house is the 87th on the street. Or rather the 88th house if we count from zero, but that's another story for another day.
$street shares its meaning with the word the in English. If I also own the house next door, I should use an array slice to say
my @houses = @street[87, 89]. Or in English, my houses are the 87th and 89th on the street. The
@street also translates to the. This doesn't help me understand the problem.
Translating this to French, or any language that inflects definite articles, provides a clearer understanding. Unless I'm horribly out of practice, we use la 87ème for the 87th and les 87ème et 89ème for the 87th and 89th. Just as French uses la (or le) for the singular and les for the plural, Perl uses
$ for the singular and
@ for the plural.
I've understood the linguistic concept of inflecting pronouns for over fifteen years, and the difference between Perl's array slices and scalars for almost ten, yet I'd never equated the two. Now that I've written this down it all seems so obvious.
I wonder whether native French speakers find this Perl idiom easier to grasp, and whether speakers of languages that don't use definite articles would prefer a programming language that lacks sigils.