Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: to sort hash wrt values corresponding to keys

by mwp (Hermit)
on Nov 02, 2011 at 06:11 UTC ( #935305=note: print w/replies, xml ) Need Help??

in reply to to sort hash wrt values corresponding to keys

It sounds like you want a hash of lists. Check out perldsc. When you write your sort function you can tell it to use an element of the child structure.

I hope I'm not doing your homework for you, but because I'm bored, beneath the spoiler is an attempt at the solution to the problem as I understand it. HTH.


Replies are listed 'Best First'.
Re^2: to sort hash wrt values corresponding to keys
by ramprasad27 (Sexton) on Nov 02, 2011 at 06:28 UTC
    my %input_hash = (key1,2,key2,3,key3,1); code:

    foreach (sort {$input_hash{$a} <=> $input_hash{$b}} keys %input_hash){ print "$input_hash{$_} \n"; }

    if at all thats what you wanted.
      thanks ramprasad!!
      this would be enough for me
Re^2: to sort hash wrt values corresponding to keys
by ansh batra (Friar) on Nov 02, 2011 at 06:17 UTC
    thanks mwp!!!
    sorry GRANDFATHER ill take care of these issues from now on!!!
    m a little lazy and a newbie too

      Laziness is good. It's a Perl virtue. But only if you think in terms of the long haul. Doing spending the time to do something right the first time is way more lazy than doing a quick and dirty job then spending endless time trying to sort the problems out.

      I spent a lot of time not answering your question, and am spending even more time now, in the hope that you will pay more attention to being actually lazy rather than superficially lazy in the future. Because at the end of the day (or month, year, ... whatever) it should take less effort for me to get your superficial laziness problem sorted out now than to endlessly ask for clarification later.

      Of course if you can't be bothered learning to be really and truly lazy I'll just give up trying to help because that's the laziest option for me. ;)

      True laziness is hard work
        ill take care from now on!!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935305]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2018-05-27 02:22 GMT
Find Nodes?
    Voting Booth?