Hi,

thanks for the suggestion. I wrote a TestFor package, pretty straight according to the documentation, as seen below. The problem persists, and besides TIEARRAY and DESTROY once and many times FETCHSIZE, there is no method called on @e.

To clarify:

The program is changed to:

#!/usr/bin/perl use strict; use warnings; use TestFor; my @e; // moved outside as suggested before tie @e, 'TestFor', 0; 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++; }

The file TestFor.pm:

package TestFor; use Carp; sub TIEARRAY { my $class = shift; my $elemsize = shift; if ( @_ || $elemsize =~ /\D/ ) { croak "usage: tie ARRAY, '" . __PACKAGE__ . "', elem_size"; } print "TIEARRAY\n"; return bless { ELEMSIZE => $elemsize, ARRAY => [], }, $class; } sub FETCH { my $self = shift; my $index = shift; print "FETCH\n"; return $self->{ARRAY}->[$index]; } sub STORE { my $self = shift; my ( $index, $value ) = @_; if ( length $value > $self->{ELEMSIZE} ) { croak "length of $value is greater than $self->{ELEMSIZE}"; } # fill in the blanks $self->EXTEND($index) if $index > $self->FETCHSIZE(); # right justify to keep element size for smaller elements $self->{ARRAY}->[$index] = sprintf "%$self->{ELEMSIZE}s", $value; print "STORE\n"; } sub FETCHSIZE { my $self = shift; #print "FETCHSIZE\n"; // was called very often return scalar @{ $self->{ARRAY} }; } sub STORESIZE { my $self = shift; my $count = shift; if ( $count > $self->FETCHSIZE() ) { foreach ( $count - $self->FETCHSIZE() .. $count ) { $self->STORE( $_, '' ); } } elsif ( $count < $self->FETCHSIZE() ) { foreach ( 0 .. $self->FETCHSIZE() - $count - 2 ) { $self->POP(); } } print "STORESIZE\n"; } sub DESTROY { print "DESTROY\n"; } 1;
Still, same problem.

In reply to Re^2: Non-deterministic behaviour with simple array initialization by thkarcher
in thread 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.