in reply to Accessing a hash of hashes in order ...

Well, you could used a tied hash. See perldoc perltie. See Tie::SortHash for an example of something similar to what you want to do. I could have sworn there was already a module to do this, but I could be mistaken.
Or consider using an array ref to keep the keys ordered, with a separate hash ref for looking up the values.
Or use a fixed-length numeric prefix on all your keys for sorting, and strip it off when displaying, etc.

Update:++Hofmator! I did a CPAN search on both 'Hash' and 'Tie' looking for something familiar, but overlooked Tie::IxHash somehow. Also, I'll have to crack open my Cookbook again in the near future :-)

  • Comment on Re: Accessing a hash of hashes in order ...

Replies are listed 'Best First'.
Re: Re: Accessing a hash of hashes in order ...
by Hofmator (Curate) on Aug 08, 2001 at 13:40 UTC

    I could have sworn there was already a module to do this, but I could be mistaken.
    Maybe you were thinking of Tie::IxHash to receive the keys in the order the elements were inserted into the hash. From the Cookbook (recipe 5.6):
    use Tie::IxHash; tie %HASH, "Tie::IxHash"; # manipulate %HASH @keys = keys %HASH; # @keys is in insertion order

    -- Hofmator