in reply to Finding Previous and Next in a HASH

One way to the answer to your question is the keys function in conjunction with sort ... you can call my @keys = sort keys %hash; to get a sorted array of the keys of the hash; while you're poking through the hash, set an index variable and grab $keys[$index-1] and $keys[$index+1] to get the keys you want.

(Of course, you should add in some checks to determine when you're at the beginning and at the end of the list of keys!).

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Replies are listed 'Best First'.
Optimized Previous and Next Accessors
by tedv (Pilgrim) on Dec 12, 2000 at 08:26 UTC
    You can get away with $keys[$index-1] and $keys[($index+1) % @keys] because the first array access, should it be negative, will access from the back of the array, and the last array access is guaranteed to be in range. So no extra checking is needed for boundaries.

    -Ted
Re: Re: Finding Previous and Next in a HASH
by myocom (Deacon) on Dec 12, 2000 at 04:59 UTC

    This is very much like what I was trying to do earlier. And this is the solution I ended up using.