use warnings; # ** use strict; # ** my $data; # ** my $c = 0; # ** my $outfile = 'tempo.pk'; # ** my $infile = shift; # ** open(IN, " < $infile" ); binmode(IN); # ** prevents newline translation my $si=2; # the number of entries is known my %matrix; while($c<$si) { # ** removed my read(IN, my $bin, 4); $data = unpack('N', $bin); my $d = Unshuffle($c); print "$c -> $d ($data)\n"; # ** $matrix{$d} += $data/3; # ** $c++; } close( IN ); open(OUT, " >$outfile" ); foreach my $d (sort {$a <=> $b} (keys %matrix)) { print "$outfile $d ($matrix{$d})\n"; # ** print (OUT pack('V', $matrix{$d})); } close( OUT ); open(IN, " <$outfile" ); # ** while( read(IN, my $bin, 4) ) { # ** $data = unpack('V', $bin); # ** print "$data:"; # ** } # ** sub Unshuffle { # ** interchange the first two positions my $val = shift; return 1 if ($val == 0); return 0 if ($val == 1); return $val; } # output was # 0 -> 1 (2140) # 1 -> 0 (1544028160) # tempo.pk 0 (514676053.333333) # tempo.pk 1 (713.333333333333) # 514676053:713: