Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: tie() weirdness

by blazar (Canon)
on Nov 22, 2005 at 13:43 UTC ( #510775=note: print w/replies, xml ) Need Help??


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

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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2022-12-07 23:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?