Perl-Sensitive Sunglasses | |
PerlMonks |
Re: sorting hashesby davido (Cardinal) |
on Mar 24, 2009 at 20:21 UTC ( [id://752960]=note: print w/replies, xml ) | Need Help?? |
I started working up an example solution and quickly realized that I'm unclear on your specification. The question I have is this: Does your hash look like this:
Or does it look like this:
Or does it look like this:
In other words, is $cols[0] to be represented in your hash as the value of $cols[0], as a reference to the element (ie, \$cols[0]), or as the literal string '$cols[0]? The last option is unlikely, but the first two are not unreasonable interpretations of your question, and yet they change the look of any example solution. Please clarify a little for us. Until we have that ironed out we can't really show you how the solution might look. Also remember that Perl's hashes are unsorted by definition. If you need to present the contents of a hash in some sorted order, you can do that on the fly, but keep in mind that if you refer back to that sorted order frequently you might find it convenient to maintain a separate sorted list; a parallel list, so to speak. In fact, your @cols array could even be an AoA that keeps track of keys and values in a sorted order such as:
You could still maintain the hash too for quick lookups. Dave
In Section
Seekers of Perl Wisdom
|
|