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.

In reply to Re: Sort a Hash 3 Levels Deep by GrandFather
in thread Sort a Hash 3 Levels Deep by Dru

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.