in reply to how do I sort on two fields in a hash table?

Another route is to rethink your data structure; if you have an array of hashs w/ each hash having 2 sort/index fields, try a hash (w/ count as the key) where the values are arrays of hashs which have type, a_point, z_point, error as members, something like:
foreach $count ( sort keys %data ){ # there's a better notation for this but $data{$count}->@ # never works for my foreachs ;-> foreach $type_hash ( @{ $data{$count} } ) { print "$count"; # just to make it easier to see, loop through the keys # for the type hash in your order. NB type_hash is # hash ref ($$type_hash) foreach $val ( (qw(type a_point z_point error) ) ) { print " --> $$type_hash{$val}"; } # foreach val print "\n"; } # foreach type_hash } # foreach count
This may be way off, for your data - the thought is that if you're having to work this hard to sort your data structure, you should think about changing your struct. Assuming you have data like:
count|type|a point|z point|error
3    |bz  |6.0    |7.2    |none
3    |boz |2.0    |1.1    |off by one
5    |bz  |3.5    |2.2    |ugly
you could:
while(<DATA>) { chomp; my ($count, $type, $a_point, $z_point, $error) = split(/\|/); push @{ $data{$count} }, {type => $type, a_point => $a_point, z_point => $z_point, error => "$error", }; } # while DATA

a