for my $key ( sort {length($b) <=> length($a)} keys %hash ) { my $value = $hash{$key}; print "$key => $value\n"; }
or more generalized using auxiliary hash:
my %order = (Number => 1, EX => 2); for my $key ( sort { ($order{$a}||1000) <=> ($order{$b}||1000)} keys % +hash ) { my $value = $hash{$key}; print "$key => $value\n"; }
Update: It's funny but your code prints 'Number' first for me without any sort procedure.
In reply to Re: Hash Order
by ccn
in thread Hash Order
by Sporti69
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |