in reply to I Ordered My Keys With Existing Values!

my @order = sort { $hash{$a} <=> $hash{$b} } keys %hash;

Or you can try Tie-InsertOrderHash-0.01.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: I Ordered My Keys With Existing Values!
by diotalevi (Canon) on Jul 28, 2003 at 15:06 UTC

    I thought that was just Tie::IxHash which is more common.

      *shrug* I did a search on CPAN for "order hash tie", and the InsertOrder module came up first. I've never found a use for keeping the insertion order on hashes, so I don't really have an opinion on either one.

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      Note: All code is untested, unless otherwise stated

Re: Re: I Ordered My Keys With Existing Values!
by abitkin (Monk) on Jul 28, 2003 at 15:14 UTC
    This is an interesting piece of code, and while it is doing exactly what I'm doing, it doesn't address the underlying problem that I was trying to represent.

    Having to do this every time I want to display this hash will require quite a bit of extra calculations. I could store this array but then I have data duplication (memory/speed tradeoff) that I was hoping to avoid.
    ==
    Kwyjibo. A big, dumb, balding North American ape. With no chin.

      With 2 to 7 data points the extra calculations are something less than "quite a bit", unless you're displaying the values many, many times. I suspect the threshold would be quite high before you noticed a slowdown.