Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

sort on values in an array of hashes

by kprasanna_79 (Hermit)
on Apr 19, 2005 at 09:07 UTC ( [id://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.
--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...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-18 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found