in reply to Re: Strange saving behaviour
in thread Strange saving behaviour

That's what i thought too...

So I put the $|=1 to force the autoflush,
BUT it doesn't explain me why the last number is truncated ?

the last numbers in my file are :
9899 9901 9907 9917 9923 9929 9931 9941 9949 9959 9967 997

notes the 3 digit number

Replies are listed 'Best First'.
Re: Re: Re: Strange saving behaviour
by ichimunki (Priest) on Feb 01, 2001 at 20:42 UTC
    You might want to include an explicit close SAVE; after the loop. Notethis will do no good. we are in an infinite loop here.
      Why ? autoflush is on, so there's no buffering !
      So everything is written in the file as soon as the value is printed ?(but how could this value be written truncated ?If it was printing number digit by digit I could understand, but it isn't the case...)

      furthermore, perl close all filehandle on exit (I know it's dirty, but the point is what a close SAVE would change here ?)

      What am I missing ?
        The real problem is your infinite loop. Stop that! I suspect ctrl-c is to blame for the truncation. (After having faithfully reproduced the error as shown) I rewrote the program as follows and got no truncated lines.
        @primes = ( 2 ); $testnumber = 3; open( SAVE, ">primes.dat" ); close SAVE; while ( 1 ) { foreach $placeholder ( @primes ) { if ( ( $testnumber / $placeholder ) =~ /^[+-]?\d+$/ ) { $testnumber = $testnumber + 2; next; } if ( $placeholder == $primes[-1] ) { push ( @primes, $testnumber ); open ( SAVE, '>>primes.dat' ) or die "Couldn't open primes.dat"; print SAVE "$testnumber\n"; close SAVE; } next; } }