Bugz has asked for the wisdom of the Perl Monks concerning the following question:
I'd like to print out the entire hash of hashes by sorting it on Category then on File and then on Name'Method1' => { 'Name' => 'ABC', 'File' => 'Beta.dat', 'Category' => 'Methods', 'Params' => 'ARGV' }, 'Method2' => { 'Name' => 'MNO', 'File' => 'Alpha.dat', 'Category' => 'Functions', 'Params' => 'ARGV' }, ... ... ... <br>
While this works, It does take a lot of time, Can someone suggest a way to do it faster?$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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Printing a Tree of Hash of hashes sorted by value
by jethro (Monsignor) on Oct 13, 2008 at 20:17 UTC | |
|
Re: Printing a Tree of Hash of hashes sorted by value
by GrandFather (Saint) on Oct 13, 2008 at 20:25 UTC | |
|
Re: Printing a Tree of Hash of hashes sorted by value
by JavaFan (Canon) on Oct 13, 2008 at 20:04 UTC | |
by Bugz (Acolyte) on Oct 13, 2008 at 20:29 UTC | |
by JavaFan (Canon) on Oct 13, 2008 at 22:20 UTC | |
|
Re: Printing a Tree of Hash of hashes sorted by value
by NetWallah (Canon) on Oct 13, 2008 at 21:28 UTC |