On Tue, Jul 24, 2001 at 02:32:18PM -0300, Silvio Luis Leite Santana wrote:
> #!/usr/bin/perl -w
> use strict;
> 
> our $PI;
> 
> $PI = \3.1415926535;
> print "(1) $PI\n";
> # prints SCALAR(0x8101f64)
> 
> $PI = 7;
> print "(2) $PI\n";
> # prints 7
> 
> *PI = \4.31415926;
> print "(3) $PI\n";
> # prints 4.31415926
> 
> $PI = \5.31419526;
> # error: Modification of a read-only value attempted at ./m2 line 18.
> print "(4) $PI\n";
> 
> And now the questions:
> 
> Question 1) Ignoring the different constant values,
> Is the first and the third attributions equivalent?

I'm not sure how you're using "attribution" here.  Do you mean assignment?

No, the first ($PI = \3.1415926535) and third (*PI = \4.31415926)
assignments are not equivalent, as evidenced by the value you get back when
you print it.  The first assignment is assigning a scalar reference to $PI,
the third is filling the scalar slot of the PI glob with the value
4.31415926.


> 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)!?

You aren't, you are filling the scalar slot of the PI glob with a value.  If
that value is a constant then $PI is read-only, because you can't change a
constant.


> Question 2) Why cannot we make the 4th attribution? What is
> making the scalar $PI a read-only?

The third assignment makes it 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...

It can be on the previous reference because "$PI = \3.1415926535" is very
different from "*PI = \4.31415926".

 
Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to