>
> $PI = \3.1415926535;
> print "(1) $PI\n";
> # prints SCALAR(0x8101f64)
because it is not dereferenced so the value is the memory location.
>
> $PI = 7;
> print "(2) $PI\n";
> # prints 7
like it should
>
> *PI = \4.31415926;
> print "(3) $PI\n";
> # prints 4.31415926\
the typeglob provides in this case provides an an auto dereference and
forces a read only (constant) variable. this is similar to inlining
functions.
sub PI () {4.3145926}
is doing the same thing. the function is prototyped to take no args, setting
a constant value to be returned.
>
> $PI = \5.31419526;
> # error: Modification of a read-only value attempted at ./m2 line 18.
> print "(4) $PI\n";
see above !!
>
> And now the questions:
>
> Question 1) Ignoring the different constant values,
> Is the first and the third attributions equivalent?
> It seems that not, but then, why?
> I thought that when I wrote
> *PI = \value
> I was giving the scalar $PI the value "reference to a value",
> and not the value itself (that is what's being printed)!?
>
> Question 2) Why cannot we make the 4th attribution? What is
> making the scalar $PI a read-only? It cannot be the
> previous reference, because we also set it to a reference on the
> first attribution, but we could change it on the second...
>
> Thanks in advance and for a long time
> Silvio Santana
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]