Hello Everyone,
I have a Hash of Hashes given as below:
'Method1' => { 'Name' => 'ABC', 'File' => 'Beta.dat', 'Category' => 'Methods', 'Params' => 'ARGV' }, 'Method2' => { 'Name' => 'MNO', 'File' => 'Alpha.dat', 'Category' => 'Functions', 'Params' => 'ARGV' }, ... ... ... <br>
I'd like to print out the entire hash of hashes by sorting it on Category then on File and then on Name
I do something like this currently
$temp1 = ""; $temp2 = ""; $temp3 = ""; for my $key1 (reverse sort { $myData{$b}{'Category'} cmp $myData{$a}{' +Category'}} keys %myData) { $temp2 = ""; my $categoryCounter=0; my $category = $myData{$key1}{'Category'}; if($temp1 !~ /$category/i){ $temp1 = $category; } for my $key2 (reverse sort {$myData{$b}{'File'} cmp $myData{$a +}{'File'}} keys %myData) { my $fileName = $myData{$key2}{'File'}; if($temp2 !~ /$fileName/i){ $temp2 = $fileName; } $temp3 =""; my $fileCounter = 0; for my $key3 (reverse sort {$myData{$b}{'Name'} cmp $myDat +a{$a}{'Name'}} keys %myData) { my $methodNo = $mydata{$key3}{'Name'}; my $fileNameInner = $mydata{$key3}{'File'}; if ($temp3 !~ /$methodNo/i) { if (($category =~ /$mydata{$key3}{'Category'}/i) & +& ($fileName =~ /$fileNameInner/i)) { if($categoryCounter == 0){ print "$category\n"; $categoryCounter++; } if($fileCounter == 0){ print "$fileName\n"; $fileCounter++; } print "$methodNo\n"; } $temp3 = $fileNameInner; } } $fileCounter = 0; } $categoryCounter = 0; }
While this works, It does take a lot of time, Can someone suggest a way to do it faster?

In reply to Printing a Tree of Hash of hashes sorted by value by Bugz

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.