in reply to Best method to order a hash of arrays
I'd be inclined to do this, which pre-codes them in the desired order:
@user_types =( [ '037' => 'member' ], [ '165' => 'public' ], [ '022' => 'staff' ], [ '683' => 'babe' ], [ '001' => 'old fart' ], );
Then you can make a hash for looking up the labels by doing
%lookup = map { @$_ } @user_types;
However, if this is something that happens a lot in your code, you might consider making your hash order-remembering, e.g. by tieing it to Tie::IxHash:
use Tie::IxHash; tie my %user_types, 'Tie::IxHash'; %user_types = ( '037' => 'member', '165' => 'public', '022' => 'staff', '683' => 'babe', '001' => 'old fart', );
Then accessing the hash via functions like keys, values, and each gives you the data in the desired order.
|
|---|