Once upon a time, when I started using arrays in Perl, I found myself wanting to write things like my $house = @street[87]. It took me a while to understand that I should use a scalar, $street[87], instead of an array slice, @street[87]. I felt that as I was dealing with an array, I should use the @ sigil.
I've noticed others making the same mistake, and I've had trouble helping others learn the difference between @ and $ in this context. In English, we might translate my $house = $street[87] 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.
So, the $ in $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 @ in @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.
It's only a foreign language (Score:2)
Well, I personaly feel lucky that the programming languages I use and my native language have very little in common.
English is a foreign language, Perl is a foreign language, C is a foreign language, Befunge is an alien language (from outer space)... I never try to "speak" Perl as I speak English. And I never ever translate Perl to French (or the other way around).
Re:It's only a foreign language (Score:1)
$array[1]and@array[1,2,3]to beginners.Close the world. txEn eht nepO
Definite Articles - Linguistics (Score:1)
Of course, Perl6 reverses it to @foo[87].
Bill
Bill
# I had a sig when sigs were cool
use Sig;
I'm wondering... (Score:1)
when the data is stored in a hash?
Here is why I ask...
I also had the problem (at first) with the array slice. I thought initially that it was a sigil issue and an issue with semantics. (As you have explained)
But, I noticed that I did not have the issue with a hash. It seemed to me that if the sigil was causing me to have a semantic problem that the problem would carry to other cases... but, in my case... it did not.
So, I thought about it so
Re:I'm wondering... (Score:1)
The
warningspragma catches this misuse nowadays, but many beginners either don't know about it or don't use it.Unfortunately, I didn't learn hashes until I had already familiarised myself with arrays, so I can't answer your first question.
Perl, French and Japanese (Score:1)
This is a comment from another French monger which doesn't have an account on user.Perl yet, and asked for someone to post it. So here it is.
-----
Well, I'm also a French native speaker and I must admit that I too made this mistake when I first learnt Perl, but I had to accept that "$" had to be used to access a single element and "@" to access the whole array. Actually, Perl's scalar and lists contexts still aren't really clear to me but the more I write Perl, the more I get used to it. I don't even try
Close the world. txEn eht nepO
sigil and plural (Score:1)
I consider that the @ sigil is the equivalent in Perl of plural in natural languages, so I use the sigil in place of plural instead of with it.
So I say @house and not @houses.
I think that other p