Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

sort on values in an array of hashes

by kprasanna_79 (Hermit)
on Apr 19, 2005 at 09:07 UTC ( #449152=perlquestion: print w/replies, xml ) Need Help??

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.

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...

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://449152]
Approved by jbrugger
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2022-11-28 19:59 GMT
Find Nodes?
    Voting Booth?