J
Jamie Smyth
I'm having some trouble printing an array in Perl. The array is very
long and must be read in by some archaic FORTRAN code so the spacing
needs to be exact. For those that speak FORTRAN, the format is
basically '(5(F16.10))'.
In perl I have:
105 my $i;
106 for ($i=0; $i<(scalar(@data)); $i++) {
107 my $s = int($i*6);
108 #print "$s $e \n";
109 $fh->printf("%10.6f %10.6f %10.6f %10.6f %10.6f\n",
110 $data[$s], $data[$s+1], $data[$s+2], $data[$s+3],
$data[$s+4]);
111 }
In addition to being rather awful looking and slow, the above code
pads a partially full, last line with zero values if the number of
elements in the array is not divisible by 5.
Is there an easier way?
Thanks.
long and must be read in by some archaic FORTRAN code so the spacing
needs to be exact. For those that speak FORTRAN, the format is
basically '(5(F16.10))'.
In perl I have:
105 my $i;
106 for ($i=0; $i<(scalar(@data)); $i++) {
107 my $s = int($i*6);
108 #print "$s $e \n";
109 $fh->printf("%10.6f %10.6f %10.6f %10.6f %10.6f\n",
110 $data[$s], $data[$s+1], $data[$s+2], $data[$s+3],
$data[$s+4]);
111 }
In addition to being rather awful looking and slow, the above code
pads a partially full, last line with zero values if the number of
elements in the array is not divisible by 5.
Is there an easier way?
Thanks.