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



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
.



Relevant Pages

  • Re: Why does Tie::Simeple (scalar) work without real local data?
    ... JWK> No, when a reference is used as a number it becomes a number: ... JWK> If you increment a reference it *becomes* a number and cannot be ... Likewise, if you stringify a ... the ref is still valid there. ...
    (comp.lang.perl.modules)
  • Re: Why does Tie::Simeple (scalar) work without real local data?
    ... JWK> If you increment a reference it *becomes* a number and cannot be ... JWK> changed back to a reference. ... Likewise, if you stringify a ... >> to a number and store it back into $x and then the ref is lost ...
    (comp.lang.perl.modules)
  • Re: Passing arguements by reference
    ... but doSomething doesnt change p unless i use "ref"? ... reference, hence both p and q pointing to the same object, not to different ... don't use the ref keyword. ... void Execute() ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Documentation suggestions
    ... > Ian> I think it would be very useful if there was reference (not just ... Lang ref as only for "language lawyers". ...
    (comp.lang.python)
  • Re: pass by reference
    ... focus has moved from insisting to use "by ref" in java-context ... independent of any other use of the word "reference" in a language. ... Just because Java-refs can be re-targetted by assignment? ... If Java had an operator to tell an Object ...
    (comp.lang.java.programmer)