Brother dsheroh has shown the correct comparison for the dataset you have provided. However, I agree with my fellow monk that the data structure is horrible. If I had to deal with this I would probably refactor it to be something more like
my $ArrayofHash = [
{
name => 'TaskA',
attrs => {
'maruti' => '20',
'honda' => '25',
'zen' => '25',
'hyundai' => '35',
'ford' => '22',
'toyota' => '11'
}
},
{
name => 'TaskB',
attrs => {
'maruti' => '11',
'honda' => '22',
'zen' => '33',
'hyundai' => '33',
'ford' => '24',
'toyota' => '16'
}
},
{
name => 'TaskC',
attrs => {
'maruti' => '12',
'honda' => '22',
'zen' => '33',
'hyundai' => '44',
'ford' => '55',
'toyota' => '66'
}
}
];
This way all of your hashrefs have known keys so it's an easier comparison to codify. eg. $a->{attrs}->{hyundai} <=> $b->{attrs}->{hyundai}
It depends on what your real dataset looks like whether or not this is an advisable approach.
|