Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Sorting HoH on 2nd level key?

by pc88mxer (Vicar)
on Jul 24, 2008 at 03:55 UTC ( #699763=note: print w/ replies, xml ) Need Help??


in reply to Sorting HoH on 2nd level key?

Your priority values are hashes. So how do you want to compare {'IS-ABC' => '3'} with {'IS-XYZ' => '3'}? Do you compare IS-ABC with IS-XYZ alphabetically, and what if they are equal?

From your desired output here's something that I think will work:

sub sortBySite { my ($site_a) = keys %{$tmp{$a}{'priority'}}; my ($site_b) = keys %{$tmp{$b}{'priority'}}; return $site_a cmp $site_b; }

Also, does your data really need to be stored as a HoH? Would this simpler structure work for you?

'hostX1-1-l.example.com' => { priority => 'IS-ABC', priority_level => 3, os => 'linux', pager => 'man-duty', }


Comment on Re: Sorting HoH on 2nd level key?
Select or Download Code
Re^2: Sorting HoH on 2nd level key?
by Anonymous Monk on Jul 24, 2008 at 04:10 UTC
    Wow! Thanks, that does the trick. I agree with you completely about the structure of the has, but I don't have control over that. Also thanks for give me a increase appreciation for the keys command.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2015-07-07 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls