Warning, a curious bug in 5.6.1 with tied variables and interpolation/concatenation, may cause some mental anguish. It seems that a double FETCH is happening, but only when the variable is interpolated at the front of a string that contains trailing characters (or the equivalent, when the variable is the leading term in a concatenation operation):

#!/usr/bin/perl -w use strict; { package Tie::IncScalar; sub TIESCALAR { my $class = shift; my $self = shift || 0; return bless \$self, $class; } sub FETCH { my $self = shift; $$self++; } sub STORE { my $self = shift; $$self = shift; } } tie my $x, 'Tie::IncScalar'; $x = 0; print "Case: 1 (good)\n"; print $x for 1..10; print "\n"; $x = 0; print "$x" for 1..10; print "\n\n"; $x = 0; print "Case: 2 (good)\n"; print " $x" for 1..10; print "\n"; $x = 0; print " " . $x for 1..10; print "\n\n"; $x = 0; print "Case: 3 (good)\n"; print " $x " for 1..10; print "\n"; $x = 0; print " " . $x . " " for 1..10; print "\n\n"; $x = 0; print "Case: 4 (yikes)\n"; print "$x " for 1..10; print "\n"; $x = 0; print $x . " " for 1..10; print "\n\n"; __END__

This produces the following output with 5.6.1:

Case: 1 (good) 0123456789 0123456789 Case: 2 (good) 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 Case: 3 (good) 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 Case: 4 (yikes) 1 3 5 7 9 11 13 15 17 19 1 3 5 7 9 11 13 15 17 19

Case 4 works fine with 5.00503 and 5.6.0. (I noticed this behaviour when playing with Tie::Cycle earlier ... same thing, skips elements in the cycle ... and if you first encounter it while playing with a two value (boolean) cycle, you may feel like you are simply whacked out because you can't see why the cycle isn't cycling :-(

I searched p5p and it appears to have been reported and patched in development versions --- I just wanted to let people here know so they might avoid some confusion if they run into it. A relevant p5p link (from which the patch is linked) is: here


In reply to warning: bug with tie (5.6.1) by danger

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.