The subroutine Unshuffle() simply calculates a new position in the output matrix for each entry. The above works until I try to scale the data, e.g. $matrix{$d} += $data/3; In which case the output is scrambled. BTW, null opperations like: $matrix{$d} += $data/1; $matrix{$d} += $data+0; still work. This, I suspect, explains the fact that the script also fails if more than one of data points added to make $matrix{$d} is non-zero. I guess that my number is now too long for the "V" template in pack. Yes, the template must be 'V', otherwise a downstream program spits the dummy. thanks againopen(IN, " < $infile" ); my $si=8192; # the number of entries is known my %matrix; while(my $c<$si) { read(IN, my $bin, 4); $data = unpack('N', $bin); my $d = Unshuffle($c); $matrix{$d} += $data; $c++; } close( IN ); open(OUT, " >$outfile" ); foreach my $d (sort {$a <=> $b} (keys %matrix)) { print (OUT pack('V', $matrix{$d})); } close( OUT );
In reply to Re: Data munging - in, out and something in between
by Anonymous Monk
in thread Data munging - in, out and something in between
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |