Hue-Bond has asked for the wisdom of the Perl Monks concerning the following question:
(This is not an XY problem, nor something that will go to production; just a question that arose while I was playing with obfuscated code).
Let's declare a constant:
*a = \"cons"; $a = "something"; print "$a\n"; __END__ Modification of a read-only value attempted at - line 2.
That's expected behaviour. Now, a little twisted:
(undef, *a) = \(undef, "cons"); $a = "something"; print "$a\n"; __END__ something
Surprise! What's that? Isn't it a constant anymore? Isn't that reference to a list, a list of references to each element? Well, let's make an explicit list of references then:
(undef, *a) = (\undef, \"cons"); $a = "something"; print "$a\n"; __END__ Modification of a read-only value attempted at - line 2.
This is expected again. But, why does the second snippet behave different?
--
David Serrano
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Ref to a list not being equivalent to a list of refs to each element
by broquaint (Abbot) on Jun 22, 2006 at 16:22 UTC | |
|
Re: Ref to a list not being equivalent to a list of refs to each element
by Fletch (Bishop) on Jun 22, 2006 at 16:21 UTC | |
|
Re: Ref to a list not being equivalent to a list of refs to each element
by davido (Cardinal) on Jun 22, 2006 at 16:55 UTC | |
|
Re: Ref to a list not being equivalent to a list of refs to each element
by Errto (Vicar) on Jun 22, 2006 at 18:23 UTC | |
by broquaint (Abbot) on Jun 23, 2006 at 17:26 UTC |