Hi monks,

I'm running perl 5.8.8 on a SuSE 10.3 Xen guest and I am observing a rather strange array behaviour with the following program:

#!/usr/bin/perl use strict; use warnings; my $i = 0; BIGLOOP: while (1) { my @e; for my $j (0..@e / 2 - 1) { print "died where I shouldn't have: $i\n"; last BIGLOOP; } $i++; }

Since @e is empty when the 'for' statement is evaluated, the "print" should never be called. Instead, it is called sooner or later, or the program dies. Some examples:

main:~ # perl for.pl 
died where I shouldn't have: 19756054
main:~ # perl for.pl 
Range iterator outside integer range at for.pl line 11.
main:~ # perl for.pl 
died where I shouldn't have: 5531064
main:~ # perl for.pl 
Illegal division by zero at for.pl line 11.
main:~ # perl for.pl 
Illegal division by zero at for.pl line 11.
main:~ # perl for.pl 
died where I shouldn't have: 24090
main:~ # perl for.pl 
died where I shouldn't have: 10987109
main:~ # perl for.pl 
died where I shouldn't have: 582219

... which means that at some point suddenly @e is not undef anymore.

I have a second VM installation on a different machine, there is no such effect. 'perl -V' is identical on those two systems. Also it's unlikely to be a memory problem: A memtest ran for hours without errors, and the very same Xen image on a different hardware shows the same problem. An strace shows also virtually no difference.

Do you have an idea how I could debug this further? Any help is appreciated.

Thank you!

Regards,
Thomas


In reply to Non-deterministic behaviour with simple array initialization by thkarcher

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.