Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

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

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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-04-20 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found