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

You might want to include an explicit close SAVE; after the loop. Notethis will do no good. we are in an infinite loop here.

Replies are listed 'Best First'.
Re: Re: Re: Re: Strange saving behaviour
by arhuman (Vicar) on Feb 01, 2001 at 20:49 UTC
    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; } }