in reply to Re: How to sort HASH?
in thread How to sort HASH?

u235sentinel,
Everyone told me I could not sort by the values

Since this is your first write-up on this site, I will assume you mean everyone somewhere else told you this. I believe this may have been a misunderstanding by you, them or likely both. You can get the keys of the hash returned to you in sorted order by any abitrary sorting method you want. The hash itself is still stored internally in its own order. This means you have to repeat the sort routine each time you want to view the hash sorted. There are modules that do the sorting for you under the covers given the appearance of a sorted hash.

I was able to sort / print the values in order

I hope you did not use the code you are showing here. You are using cmp when you should be using <=>. The difference is textual comparison versus numerical. Do you really want 2 coming after 10?

Welcome to the Monastery! - L~R

Replies are listed 'Best First'.
Re: Re: Re: How to sort HASH?
by u235sentinel (Hermit) on Apr 05, 2004 at 21:43 UTC
    oops ..

    Yes I did use this code and now I see I was a 'little' too quick to push it out. But then again, I'm a noob still. Thx for the tip. I made the change and tested it against my access list. So cmp does a text comparison? That part was unclear. :-)

    I will assume you mean everyone somewhere else told you this

    Yup. It was in speaking with my co-workers. Seems I was lead astray :-)

    Thx again!