in reply to Sort a Hash 3 Levels Deep

SuicideJunkie hints at the solution for you in Re: Sort a Hash 3 Levels Deep, but you may need a little elaboration. The following mocks up your data structure, generates a sorted list of keys, then uses your sample for loop to print the result:

use strict; use warnings; my %siteInfo; while (<DATA>) { chomp; my @parts = split; my $site = ($siteInfo{"Site$."} = {}); @{$site}{qw(region country city)} = @parts; $site->{totalS5s} = $site->{totalVulns} = ++$site->{totalDevices}; } my @sorted = sort { my $siteA = $siteInfo{$a}; my $siteB = $siteInfo{$b}; $siteA->{region} cmp $siteB->{region} or $siteA->{country} cmp $siteB->{country} or $siteA->{city} cmp $siteB->{city} } keys %siteInfo; for my $site1 (@sorted) { my $site = $siteInfo{$site1}; print "$site->{region},$site->{country},$site1,$site->{totalDevice +s}, ,$site->{totalVulns},$site->{totalS5s}\n"; } __DATA__ ...

Prints (if you replace ... above with the sample data):

APAC,Australia,Site3,1, ,1,1 APAC,China,Site7,1, ,1,1 APAC,China,Site2,1, ,1,1 APAC,India,Site1,1, ,1,1 APAC,Japan,Site4,1, ,1,1 EMEA,France,Site9,1, ,1,1 EMEA,Germany,Site8,1, ,1,1 EMEA,Italy,Site15,1, ,1,1 EMEA,Italy,Site10,1, ,1,1 EMEA,Russia,Site6,1, ,1,1 EMEA,SouthAfrica,Site5,1, ,1,1 NLAM,Argentina,Site11,1, ,1,1 NLAM,Brazil,Site13,1, ,1,1 NLAM,USA,Site14,1, ,1,1 NLAM,USA,Site16,1, ,1,1 NLAM,USA,Site12,1, ,1,1

Perl's payment curve coincides with its learning curve.

Replies are listed 'Best First'.
Re^2: Sort a Hash 3 Levels Deep
by Dru (Hermit) on Dec 10, 2008 at 17:43 UTC
    Thank you. That is what I was trying to do.

    Dru

    Perl, the Leatherman of Programming languages. - qazwart