in reply to Re^9: Thx, St. Larry, for the Beauty of Sigils
in thread Thx, St. Larry, for the Beauty of Sigils
Well yes that's how it's implemented in Perl - and other languages like Python or JS too - but doesn't help comparing languages.
They all store references into their "namespaces" or "lexical pads"
...and anonymous" only refers to the literal array or {hash} constructors not to the scalar on the LHS of an assignment.
perldata states:
Values are usually referred to by name, or through a named reference.
So the LHS in $ary = [1,2,3] is a named reference; it is a named variable. The RHS is an anonymous array, at least that is what is called throughout the perl documentation. So let's stick to that to avoid confusion.
The difference is not "named" or "unnamed", but explicit or implicit dereferencing.
Difference between languages, but not in perl.
In perl, the scalar $ary may hold an anonymous array. But @ary is a named array. Perl does no implicit derefrencing, and so the syntax to access slots of the named array @ary necessarily has to be distinct from the one to access a slot of the anonymous array stored in the named scalar variable $ary - or of any anonymous array:
my $result = [ func(@args) ]->[2];
So in perl - at least that is how I understand perl for a couple of decades now - the difference is between named and anonymous variables. To get hold of an anonymous variable beyond a single statement, its reference has to be stored in a named scalar variable.
But I'm not going on telling you stuff you know as well as I do, only to get reverse 'halb' back, and I won't argue any more, since there is no point but frustration. Let's close this sub-thread. Thank you.
update
°) or scalars, but this can't be easily written *scalar = \1 is not the same thing
Of course not, because that makes a reference from a constant. A variable reference is needed to make it variable:
*scalar = \do { my $x = 1 };
The expression *scalar = \"foo bar" creates a package constant (readonly package variable) $scalar (but *scalar = \"Hello $world" doesn't, it's r/w :-).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^11: Thx, St. Larry, for the Beauty of Sigils
by LanX (Saint) on Jul 28, 2019 at 10:36 UTC | |
by shmem (Chancellor) on Jul 28, 2019 at 10:46 UTC |