Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: tie() weirdness

by Animator (Hermit)
on Nov 21, 2005 at 12:16 UTC ( #510426=note: print w/replies, xml ) Need Help??


in reply to Re^2: tie() weirdness
in thread tie() weirdness

It certainly is a strange thing. This post lists some more strange things and no solution. Something certainly was changed (between v5.6 and v5.8)... what I don't know.

If you run your latest code on v5.6.1 then you'll see that FETCH is called 4 times, not three times. (and it prints 123).

If you change it into print $s . $s . $s; then you get 123 on v5.6, and 112 on v5.8.

Change it into: print "" . $s . $s . $s; and you get 012. (on v5.6 and v5.8)

Change it into: print "$s$s" . "$s$s" . "$s$s" and you get 124578 on v5.6 and 113355 on v5.8.

There is another case in which the scalar is evaluated twice (and that I didn't immediatly see in here/the links posted here): hash keys on v5.6. If the key does not exist then it will re-evaluate the scalar. And the last value will be used for the key. This seems to be fixed in v5.8.

If this was 'normal' code I would strongly advice against using such a construct, since there are too many cases where it can go wrong...

And if you look at the perlapi then you will find function that evaluate it twice aswell... (for example SvIV and SvIVx)

Update: Some other 'strange' cases:

  • print $s . "$s$s" : v5.6: FETCH is called 5 times and the output is 412. v5.8: FETCH called 3 times and the output: 211.
  • print $s . "$s" . $s: v5.6: output 203. v5.8 output: 102. (The output of print $s.$s.$s is mentioned above)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://510426]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2022-12-05 11:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?