Hi there,
I had a pop at this, and ended up with a solution that's a bit too much like line noise. Anyway, here you go:
#!/usr/bin/perl use warnings; use strict; #Your data, I messed with the Group attribute to test my code. my $hoh = { '1018884184639' => { 'Group' => 'Marketing', 'System Name' => '1018884184639', 'Authorization' => 'mrossa' }, '1017939213033' => { 'Group' => 'Marketing', 'System Name' => '1017939213033', 'Last Update' => 'Thu Apr 18 14:29:30 2002', 'Support Tools' => 'EGstools', 'Source Code Management' => 'EGscm', 'Production Platforms' => 'EGpp', 'Design Tools' => 'EGdest', 'Authorization' => 'dsmith', 'Test Tools' => 'EGtt', 'Database' => 'EGdb', 'URL' => 'http://www.perlmonks.com', 'Middleware' => 'EGmidd', 'Database Tools' => 'EGdb', 'Found Internal Libraries' => 'EGfdxi', 'Development Languages' => 'EGdl', 'Development Tools' => 'EGdtools', 'Fail Over Software' => 'EGfos' }, '1017939028902' => { 'Group' => 'Shipping', 'System Name' => '1017939028902', 'Last Update' => 'Fri Mar 29 10:32:44 2002', 'Support Tools' => '9', 'Source Code Management' => '10', 'Production Platforms' => '1', 'Design Tools' => '12', 'Authorization' => 'ecartman', 'Test Tools' => '11', 'Database' => '4', 'URL' => 'http://www.osdncom', 'Middleware' => '2', 'Database Tools' => '5', 'Found Internal Libraries' => '7', 'Development Languages' => '6', 'Development Tools' => '8', 'Fail Over Software' => '3' }, }; #We have a hash of system hashes, and we want to sort/group by the key +s within #the system hashes. #First, find out what attributes you're going to sort/group by my %sorted_by_attribute; #Loop through all the systems foreach my $system (keys %$hoh) { #Loop through all the keys found within each system, eg 'Devel +opment Tools' foreach my $attribute (keys %{$hoh->{$system}}) { #Get the value of that key, eg '8', and push the syste +m name onto #an array which is unique to that attribute, then the +value of that attribute my $attribute_value = $hoh->{$system}{$attribute}; push @{$sorted_by_attribute{$attribute}{$attribute_val +ue}}, $system; #Offhand, $sorted_by_attribute{$attribute}{$attribute_ +value} is an array reference, #hence the deref'ing curlies and @ symbol. (You can't +put a straight array into #a hash) } } #Now %sorted_by_attributes looks like this: #$VAR1 = { # 'Group' => { # 'Marketing' => [ # '1017939213033', # '1018884184639' # ], # 'Shipping' => [ # '1017939028902' # ] # }, # . # . # . # } #Print the data foreach my $attribute (sort keys %sorted_by_attribute) { my $individual_values = $sorted_by_attribute{$attribute}; print $attribute, "\n"; foreach my $value (keys %$individual_values) { my @systems = @{$sorted_by_attribute{$attribute}{$valu +e}}; print $value, " := "; print join ", ", @systems; print "\n"; } print "\n"; }
Blech.
Hopefully the comments are enough to allow you to understand it
cheers

davis
Is this going out live?
No, Homer, very few cartoons are broadcast live - it's a terrible strain on the animator's wrist
Update: Fixed missing octothorp for comment. D'oh.

In reply to Re: Data Structures and Sorting by davis
in thread Data Structures and Sorting by data67

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.