Kent Fredric <[email protected]> writes:
> On 26 May 2017 at 05:33, lee <[email protected]> wrote:
>> Perl doesn't have data structures, so variables in perl are not data
>> structures. That is unfortunate.
>
>
> So when I write:
>
> my $var = {
> memory => {
> total => 1024,
> free => 100,
> buffers => 10,
> },
> };
>
>
> What do I have?
You have a variable.
> Because as far as I'm concerned, I have both data structures and
> references in play.
As far as I'm concerned, you seem to have assigned a reference to the
variable, and what it might be referring to is difficult to figure out.
Some sort of construction that resembles a hash seems involved. As far
as I'm concerned, hashes are key/value pairs. I don't consider them as
data structures any more than, for example, an integer. They are a
given element of the language which can be useful when you have a bunch
of values you want to refer to by names.
So I'm not sure what you have there.
> References are not a low level mechanic that only the Perl VM needs to
> care about.
>
> References are a mechansim to allow data structures to be passed
> *without copying*
Yes, that works nicely in C.
> my $x = 5;
> my $y = $x; # x is a copy of y
>
> However, if I do:
>
> my $x = 5;
> $y = \$x
>
>
> Y is now a reference to X
$y = 5;
Now $y is 5. That is what's evil.
> If I now do:
>
> ${$y} = 10
>
> X changes.
Yes, and that's a horrible notation.
> Its a useful tool, that programmers have uses for.
>
> If you think they're evil, then you're probably thinking too much in C.
They are evil in perl because the notation is unwieldy, especially when
you need to de-reference a reference. That they are indistinguishable
from non-references doesn't help.
Perhaps I do think too much in C --- at least such things are much
easier to deal with there. It could be easier in perl, too.
> Because you can't do any real work in perl *without* references.
Why is that? Because arrays are transformed into lists when passed as
arguments to functions?
What do you consider "real work"?
> *Objects* in perl are blessed references.
I don't know yet what "blessed" is supposed to mean.
> Avoid that all you like, but you're just avoiding using Perl and
> wondering why it hurts :)
I'm using it a lot, and it doesn't hurt. It's even fun to use. It also
has advantages for what I'm using it for, which is why I'm using it.
--
"Didn't work" is an error.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/