sorting - Group Perl object by child nodes -


i have object in format shown below, , need group them available months. 1000, 2000, ect. amounts in dollars, , next level (6, 4) months.

my object:

$var1 = {           '1000' => {                       '6' => {                                'apr' => '13.9'                              },                       '4' => {                                'apr' => '11.9'                              }                     },           '2000' => {                       '6' => {                                'apr' => '13.9'                              },                       '4' => {                                'apr' => '11.9'                              }                     },           '4000' => {                       '6' => {                                'apr' => '13.9'                              },                       '4' => {                                'apr' => '11.9'                              }                     }           '5000' => {                       '6' => {                                'apr' => '13.9'                              }                     }         }; 

the object want:

$var1 = {     '6' => {              '1000',              '2000',              '4000',              '5000'            },     '4' => {              '1000',              '2000',              '4000'            } } 

my %new_hash; $amount (sort { $a <=> $b } keys(%$var1)) {    $month (keys(%{ $var1->{$amount} })) {       push @{ $new_hash{$month} }, $amount;    } } 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -