in reply to volatile memory?

Unless you use parallel threads which mysteriously change the value of $buffer, I don't think that Perl gets "out of sync" when writing your memory. You did not specify at which point $buffer is not equal to $array[0]. Of course there are some parts in your program where these variables are potentially not equal (for example, during the execution of mytestfunc).

BTW, are you sure that we are talking about numerical unequality, and not string unequality? I.e., $buffer contains always a number, right? Because you are using != and not ne.

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: volatile memory?
by kjcdb8er (Initiate) on Sep 02, 2010 at 08:11 UTC

    I'm not intentionally using multiple threads, though the computer is dual core.

    The error occurs within the loop; every so often, $array[0] contains the wrong value (yes, numeric), but always a previously used value. In tests, only about 20% of the values were wrong, the others right. And the second while loop solved the errors. I don't know how to explain that, really.

    mytestfunc only reads values from the array, and does not change it.

      Hi kjcdb8er, I just set up a little test to prove the fast assignment and reassignment of values in the array:
      # 858508.pl use strict; use warnings; use 5.010; my @array_old = my @array = ( 1 .. 10e3 ); for my $i ( 0 .. $#array ) { my $buffer = $array[$i]; $array[$i] = new_value(); $array[$i] = $buffer; } if( @array_old ~~ @array ) { say "arrays are equal"; } else { say "array are different"; } sub new_value { rand(); }
      This code creates an array of consequtive numbers from 1 to 10000 and changes every number to a random value and restores the initial value. I wasn't able to reproduce your problem. I suppose the problem you are facing is located on the different code part as you showed.
      You can post the complete code so that others can run your code on their machine.