Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hashes can't be sorted b/c they have no order.

But you can keep sorted arrays of keys or values.

Your wish to keep the "path"s of a HoAoH sorted is a strong indication for me that you might wanna check the multi-dim hashes we inherited from Perl4.

Like this you could flatten your data to a 1-dim hash

$hash{$key0,$idx0,$key1}=<some floating point value>

and keep an array of sorted @keys .

Looks far simpler for me! (effectively it's using your concat approach w/o the overhead of the origanal HoAoH)

If you need this more often you might wanna check on tiehash solutions on CPAN to allow sorted hashes by encapsulating the sorted @keys .

HTH =)

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

edit

fixed syntax error by 's/;/,/'


In reply to Re: sorting hash of array of hashes by value by LanX
in thread sorting hash of array of hashes by value by Special_K

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2021-10-26 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (91 votes). Check out past polls.

    Notices?