The output I get is this:#!/usr/bin/perl -w use strict; my %tmp = ( 'hostX1-1-l.example.com' => { 'priority' => { 'IS-ABC' => '3', }, 'os' => { 'linux' => 'linux', }, 'pager' => { 'man-duty' => 'man-duty', }, }, 'hostC1-3-l.example.com' => { 'priority' => { 'IS-XYZ' => '3', }, 'os' => { 'linux' => 'linux', }, 'pager' => { 'man-duty' => 'man-duty', }, }, 'hostc1-3-l.example.com' => { 'priority' => { 'OS-XYZ' => '3', }, 'os' => { 'linux' => 'linux', }, 'pager' => { 'man-duty' => 'man-duty', }, }, 'hostC1-9-l.example.com' => { 'priority' => { 'XS-XYZ' => '3', }, 'os' => { 'linux' => 'linux', }, 'pager' => { 'man-duty' => 'man-duty', }, }, 'hostH1-2-l.example.com' => { 'priority' => { 'IS-XYZ' => '3', }, 'os' => { 'linux' => 'linux', }, 'pager' => { 'man-duty' => 'man-duty', }, }, 'hostQ1-3-l.example.com' => { 'priority' => { 'IS-ABC' => '3', }, 'os' => { 'linux' => 'linux', }, 'pager' => { 'man-duty' => 'man-duty', }, }, ); sub sortBySite { my $site_a = $tmp{$a}{'priority'}; my $site_b = $tmp{$b}{'priority'}; return $site_a <=> $site_b; } #foreach my $host ( sort { $tmp{$a}{'priority'} <=> $tmp{$b}{'priority +'} } sort keys %tmp ) { #foreach my $host ( sort keys %tmp ) { foreach my $host ( sort sortBySite keys %tmp ) { for my $site ( keys %{ $tmp{$host}{'priority'}} ) { print "$host->$site is $tmp{$host}{'priority'}{$site}\ +n"; } }
What I am try to get is this:hostX1-1-l.example.com->IS-ABC is 3 hostC1-3-l.example.com->IS-XYZ is 3 hostc1-3-l.example.com->OS-XYZ is 3 hostC1-9-l.example.com->XS-XYZ is 3 hostH1-2-l.example.com->IS-XYZ is 3 hostQ1-3-l.example.com->IS-ABC is 3
ThankshostQ1-3-l.example.com->IS-ABC is 3 hostX1-1-l.example.com->IS-ABC is 3 hostC1-3-l.example.com->IS-XYZ is 3 hostH1-2-l.example.com->IS-XYZ is 3 hostc1-3-l.example.com->OS-XYZ is 3 hostC1-9-l.example.com->XS-XYZ is 3
In reply to Sorting HoH on 2nd level key? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |