AQ> AFAIK, that was how Larry Wall originally designed it, and it stayed
AQ> this way for backward compatibility. The introduction of reference
AQ> with Perl5 was specifically targeted at adding the ability to build
AQ> nested data structures.
and even without that, it makes very good sense. the problem with
Indeed!
As a side note, even if I have not had any exposure to Perl4 but in
terms of corrections to old(-fashioned)/obsolete scripts, I'm
fascinated by the way these extremely powerful features were added in
a manner not only backwards-compatible with previous relases of the
language, but even consistent with them, that is with Perl's basic
syntax that we all, presumably, appreciate so much!
storing a real hash where a scalar is, is how do you store it? the slot
in an SV can hold a single item (a scalar) so what would you put there
to represent a hash? and if any of those hash elements was a hash, all
memory hell breaks out. in c, you can only do multidim arrays of known
Well, as far as the UI is concerned the "look and feel" of references
is exacly this, i.e., loosely speaking (about a subset of the meanings
that can be given to refs), of "arrays and hashes that can be stored
into a single scalar variable".
IMHO the only situation when the fake nature of refs as nested
structures becomes evident is with "copy": it's not so bad in the end,
and we all do such things routinely either with our own handmade
solutions or by means of a cloning module, but that's it!
Now that I come to think of this, IMHO it would be fine if an
assignement operator existed (what about ':=') that does an automatic
recursive copy/cloning of its RHS. Or even better, an operator to
return such a clone... what about:
<-
Hmmm, no, would be an hell for a parser to tell from "less than,
minus",
<--
no, same cmt,
<=
no, already taken! (and context wouldn't help much here, I guess),
<==
Hmmm, well, what about this?
my @AoA = ([1,0], [0,1]);
my @new_AoA = <== @AoA;
$new_AoA[0][1]=1; # it's now ([1,1], [0,1]), @AoA unchanged
element size. with perl you can have each thing at any level be any
thing of any size. so the win is major flexibility at a cost of
understanding and dealing with refs. not a bad tradeoff IMO.
^^^^^^^^^^^^^^^^^^^^^^
Definitely, IMO too!
Also, it seems that in Perl6 dealing with references will be made much
more transparent, won't it?
Michele,
whose judgement capabilities may be strongly biased/injured by our
traditional Easter lunch...