Hello Monks,
I need help with a complex (well for me anyway) sort routine. I have a hash that has various elements, and 3 of those elements are the region, country, and city. Right now I am sorting on the region, but I also need to sort on the country next, and city last.
So, for the following data:
APAC India Delhi
APAC China Suzhou
APAC Australia Sydney
APAC Japan Tokyo
EMEA SouthAfrica Johannesburg
EMEA Russia Moscow
APAC China Shanghai
EMEA Germany Munich
EMEA France Paris
EMEA Italy Venice
NLAM Argentina BuenosAires2
NLAM USA NYC
NLAM Brazil San Paulo
NLAM USA Austin
EMEA Italy Rome
NLAM USA Boston
I need it to be sorted as such:
APAC Australia Sydney
APAC China Shanghai
APAC China Suzhou
APAC India Delhi
APAC Japan Tokyo
EMEA France Paris
EMEA Germany Munich
EMEA Italy Rome
EMEA Italy Venice
EMEA Russia Moscow
EMEA SouthAfrica Johannesburg
NLAM Argentina BuenosAires2
NLAM Brazil San Paulo
NLAM USA Austin
NLAM USA Boston
NLAM USA NYC
Here is where I am extracting my hash and how I sort based on region
sub print_stats{
my $subinput = $_[0];
for my $site1 (keys %siteInfo){
#Site has to be in correct region
next unless ($siteInfo{$site1}{region} eq $subinput);
print "$siteInfo{$site1}{region},$siteInfo{$site1}{country},$site1,
$siteInfo{$site1}{totalDevices}, ,$siteInfo{$site1}{totalVulns},
$siteInfo{$site1}{totalS5s},";
}
}
}
Thanks,
Dru
Perl, the Leatherman of Programming languages. -
qazwart
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.