I agree with the other monks that you probably should use a better data structure. However, you can use the Schwartzian Transform described in the FAQ to solve the original problem.
$type 1227601.pl use strict; use warnings; use Data::Dumper; my $ArrayofHash = [ { 'TaskA' => { 'maruti' => '20', 'honda' => '25', 'zen' => '25', 'hyundai' => '35', 'ford' => '22', 'toyota' => '11' } }, { 'TaskB' => { 'maruti' => '11', 'honda' => '22', 'zen' => '33', 'hyundai' => '33', 'ford' => '24', 'toyota' => '16' } }, { 'TaskC' => { 'maruti' => '12', 'honda' => '22', 'zen' => '33', 'hyundai' => '44', 'ford' => '55', 'toyota' => '66' } } ]; my $sorted = [ map {$_->[1]} sort {$b->[0] <=> $a->[0]} #map {(my $h) = values %$_; [$h->{hyundai}, $_]} map {[(values %$_)[0]{hyundai}, $_]} @$ArrayofHash ]; print Dumper($sorted); $perl 1227601.pl $VAR1 = [ { 'TaskC' => { 'zen' => '33', 'toyota' => '66', 'maruti' => '12', 'hyundai' => '44', 'honda' => '22', 'ford' => '55' } }, { 'TaskA' => { 'ford' => '22', 'toyota' => '11', 'maruti' => '20', 'hyundai' => '35', 'honda' => '25', 'zen' => '25' } }, { 'TaskB' => { 'ford' => '24', 'honda' => '22', 'hyundai' => '33', 'maruti' => '11', 'toyota' => '16', 'zen' => '33' } } ]; $

UPDATE: Modified code to simplify dereference. Note: Using the first (and only) element of values avoids the problem with not knowing the name of the key.

Bill

In reply to Re: need to sort array of hash by BillKSmith
in thread need to sort array of hash by Anonymous Monk

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.