Re: Why does Tie::Simeple (scalar) work without real local data?



"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
.