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: