Done!

I received two answers pasted hereafter. According to the former it has been solved in bleædperl; according to the latter it doesn't really have to do with tie but with the use of "the same variable more than once in an expression, where use of that variable has side effect". This sheds some light on the extremely concise reply by Anonymous Monk, since the thread referenced there goes into some detail discussing related topics.

To be fair the second email also claims that it "isn't actually a bug", which IMHO does conflict both with almost everyone here's perception (certainly it does not DWIM - now it may just be a misconceived dwimmery, but since it does apply as intended in practically identical situations, this doesn't seem to be the case!) and the claim of the first one that it has been solved.

The answers

Answer #1
Date: Mon, 21 Nov 2005 09:47:02 -0800 From: Rafael Garcia-Suarez via RT <perlbug-followup@perl.org> Subject: [perl #37722] interpolated tie()d variable weirdness This has been fixed in bleadperl by change #26185.
Answer #2
Date: Mon, 21 Nov 2005 11:36:54 -0800 From: Dave Mitchell via RT <perlbug-followup@perl.org> Subject: Re: [perl #37722] interpolated tie()d variable weirdness On Mon, Nov 21, 2005 at 03:21:13AM -0800, Michele Dondi wrote: > I noticed a strange and appearently inconsistent behaviour (to the b +est of > my knowledge non documented) when a tie()d variable is put at the *b +eginning* > of an iterpolating string. Minimal example code follows: > > > #!/usr/bin/perl -l > > use strict; > use warnings; > > sub TIESCALAR { bless \my $i, shift } > sub FETCH { ${shift,}++ } > > tie my $s, 'main'; > print "$s$s$s"; > print "$s$s$s"; > > tie my $t, 'main'; > print " $t$t$t"; > print " $t$t$t"; > > __END__ > > > Output: > > > 112 > 445 > 012 > 345 > > Thanks for the report, but this isn't actually a bug! Similar sorts of effects can be seen without tie, eg $ perl -le 'print ++$x . ++$x . ++$x' 223 $ perl -le 'print " " . ++$x . ++$x . ++$x' 123 $ Note that interpolated strings are just short hand for string concats, + and in fact that's how perl handles them internally, ie " $s$s$s" is equivalent to (("".$s).$s).$s and in general when you when you start using the same variable more th +an once in an expression, where use of that variable has side effect, unexpected things will generally happen. -- Never do today what you can put off till tomorrow.

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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.