Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How to sort Hashes of Hashes and print results in a file

by kirillm (Friar)
on Mar 27, 2009 at 23:34 UTC ( [id://753806]=note: print w/replies, xml ) Need Help??


in reply to How to sort Hashes of Hashes and print results in a file

Well, by definitions hashes are unordered collections. You could e.g. get an ordered list/array of key/value pairs or whatever, but they won't be hashes. Or you could use Tie::Hash::Indexed or Tie::IxHash to get ordered hashes.

Regarding your questions, I hope you can re-phrase them.

-- Kirill

  • Comment on Re: How to sort Hashes of Hashes and print results in a file

Replies are listed 'Best First'.
Re^2: How to sort Hashes of Hashes and print results in a file
by stan131 (Acolyte) on Mar 27, 2009 at 23:49 UTC
    Ok let me rephrase. Here is my hash
    %hash{ a => {doc1=>'2.0', doc2=>'4.5', doc7=>'3.0' }, b => { doc2 => '3.5', doc10 => '6.5', doc7 => '11.4', doc20 => '0.5' } }

    Now for 'a' I need to retrieve top 2 doc with highest value.
    In this case it will be 'doc2' and 'doc7'
    In case of 'b' it will be 'doc7' and 'doc10'
    Number of docs will differ in 'a' and 'b'.
    Does this clarify my question
      I've run my script and the result was:
      -> a
      --> doc2: 4.5
      --> doc7: 3.0
      
      -> b
      --> doc7: 11.4
      --> doc10: 6.5
      
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://753806]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 16:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found