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??

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



  • 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 about the Monastery: (3)
As of 2024-04-13 04:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found