Store the order you want in an array.
$ perl -Mstrict -Mwarnings -E ' my %people; $people{ Fred }->{ age } = 37; $people{ Fred }->{ sex } = q{male}; $people{ Fred }->{ occ } = q{plumber}; $people{ Mary }->{ age } = 41; $people{ Mary }->{ sex } = q{female}; $people{ Mary }->{ occ } = q{barmaid}; my @order = qw{ age sex occ }; foreach my $person ( keys %people ) { say qq{$person:}; foreach my $attr ( @order ) { say qq{ $attr: $people{ $person }->{ $attr }}; } }' Mary: age: 41 sex: female occ: barmaid Fred: age: 37 sex: male occ: plumber $
I hope this is helpful.
Cheers,
JohnGG
In reply to Re: Sorting a hash in a predetermined order
by johngg
in thread Sorting a hash in a predetermined order
by edimusrex
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |