[tpm] Modification of a read-only value
Stuart Watt
stuart at morungos.com
Thu Apr 22 18:57:50 PDT 2010
A simpler example of how to use a scalar reference is:
> perl -le 'my $y = 0; my $x = \$y; $$x++; print $$x'
Basically, the error tells you that the code is actually trying to modify the constant string "0", and you're not allowed to do that. The example here might help you.
All the best
Stuart
On 2010-04-22, at 9:39 PM, Shaun Fryer wrote:
> I'm curious why a scalar reference is considered a read-only value?
>
> $ perl -le 'my $x = \"0"; $$x++; print $$x'
> Modification of a read-only value attempted at -e line 1.
>
> $ perl -le 'my $x = {x=> 0}; $x->{x}++; print $x->{x}'
> 1
>
> Is there an easy way to update a simple scalar ref without having to
> use an array or hash ref instead?
>
> Fyi... This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
> --
> Shaun Fryer
> _______________________________________________
> toronto-pm mailing list
> toronto-pm at pm.org
> http://mail.pm.org/mailman/listinfo/toronto-pm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/toronto-pm/attachments/20100422/23c817b3/attachment.html>
More information about the toronto-pm
mailing list