Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Uri Guttman <uri@xxxxxxxxxxxxxxx>
- Date: Tue, 05 Dec 2006 13:02:32 -0500
"JWK" == John W Krahn <someone@xxxxxxxxxxx> writes:
JWK> No, when a reference is used as a number it becomes a number:
JWK> $ perl -le'$x = {}; print for ref $x, $x, $x + 0'
JWK> HASH
JWK> HASH(0x816cc20)
JWK> 135711776
you forgot to print $x after the +0.
perl -le'$x = {}; print for ref $x, $x, $x + 0, $x'
HASH
HASH(0x11d910)
1169680
HASH(0x11d910)
JWK> If you increment a reference it *becomes* a number and cannot be
JWK> changed back to a reference. Likewise, if you stringify a
JWK> reference it cannot be changed back to a reference.
incorrect.
perl -le'$x = {}; print for ref $x, $x, $x + 0, "$x", ref $x'
HASH
HASH(0x11d910)
1169680
HASH(0x11d910)
HASH
the stringified value can't be used as a ref but it doesn't change the
original value to a string. the ref is still valid there.
the difference with the OP's code is that ++ will change the ref value
to a number and store it back into $x and then the ref is lost
forever. just using a ref in some expression without modifiying it will
not change the ref.
uri
--
Uri Guttman ------ uri@xxxxxxxxxxxxxxx -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
.
- Follow-Ups:
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: John W. Krahn
- Re: Why does Tie::Simeple (scalar) work without real local data?
- References:
- Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Dr.Ruud
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Dr.Ruud
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Mumia W. (reading news)
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: John W. Krahn
- Why does Tie::Simeple (scalar) work without real local data?
- Prev by Date: Re: Sort::Maker : anonymous sub is compiled outside of my module
- Next by Date: Re: Spread***::Read special characters handling
- Previous by thread: Re: Why does Tie::Simeple (scalar) work without real local data?
- Next by thread: Re: Why does Tie::Simeple (scalar) work without real local data?
- Index(es):