Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

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)

In reply to Re^3: tie() weirdness by Animator
in thread tie() weirdness by blazar

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.