Re: Why does Tie::Simeple (scalar) work without real local data?
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Tue, 05 Dec 2006 19:40:07 GMT
Uri Guttman wrote:
"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.
That's what I thought I was saying. Unfortunately the code I used did not
convey that point. :)
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- Follow-Ups:
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Uri Guttman
- 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
- Re: Why does Tie::Simeple (scalar) work without real local data?
- From: Uri Guttman
- 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: Sort::Maker : anonymous sub is compiled outside of my module
- 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):
Relevant Pages
|