in reply to how do I sort on two fields in a hash table?
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: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
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 |uglyyou 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
|
---|