http://www.perlmonks.org?node_id=449152

kprasanna_79 has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,
i have an array of hashes, in which i want to sort the array with values of the hashes.
push (@found, {name => $1}) if(/*.pm/); ...

i want the @found array to be sorted on the values of hash.
I seek your wisdom in this respect.
--prasanna.k

Replies are listed 'Best First'.
Re: sort on values in an array of hashes
by ambs (Pilgrim) on Apr 19, 2005 at 09:09 UTC
    Not sure if what you want is this...
    @array = sort { $a->{name} cmp $b->{name}} @found;
    Good luck

    Alberto Simões

Re: sort on values in an array of hashes
by blazar (Canon) on Apr 19, 2005 at 09:28 UTC
    push (@found, {name => $1}) if(/*.pm/);
    Except that this won't even compile and if it did, then it would be pointless to use $1 for there are no capturing parens. Hint: regexen are not shell patterns.

    Hint no. 2: post real code when asking for help.

    PS: slight smell of XY here...