Liste des Groupes | Revenir à l misc |
On 10/10/2024 17:55, Rainer Weikusat wrote:Muttley@DastartdlyHQ.org ignorantly rambled:>On Thu, 10 Oct 2024 16:09:49 +0100For the purpose of variable declaration, how's the interpeter going
Rainer Weikusat <rweikusat@talktalk.net> boring babbled:Muttley@DastartdlyHQ.org writes:>Its syntax is also a horrific mess.>
Which means precisely what?
Far too much pointless punctuation. An interpreter shouldn't need the vartype
signified by $ or @ once its defined, it should already know.
to
know the type of a variable without being told about it? Obviously, not
at all.
Perl has three builtin types, scalars, arrays and hashes and
each is denoted by a single-letter prefix which effectively creates
three different variable namespaces, one for each type. That's often
convenient, because the same name can be reused for a variable of a
different type, eg:
my ($data, @data, %data);
Why would you want to do this?
$data = rand(128);>
@data = ($data, $data + 1);
%data = map { $_, 15 } @data;
it's also convenient to type and easy to read due to being concise.
Adding shifted punctuation at the start of every instance of a
variable? I don't call that convenient!
So, $ is scalar, @ is an array, and % is a hash?
Outside of declarations, $ and @ really denote access modes/ contexts,>
with $ standing for "a thing" and @ for "a number of things", eg
$a[0]is the first element of the array @a and>
Now I'm already lost. 'a' is an array, but it's being used with $?
What would just this:
>
a[0]
>
mean by itself?
@a[-3 .. -1]>
is a list composed of the three last elements of @a.
Sorry, these prefixes look utterly pointless to me. This stuff works
perfectly well in other languages without them.
>
I can write a[i..j] in mine and I know that it yields a slice.
What would $a[-3 .. -1] mean?
What happens if you have an array of mixed scalars, arrays and hashes;
what prefix to use in front of a[i]?
Les messages affichés proviennent d'usenet.