Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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.

mwp


Comment on Re: to sort hash wrt values corresponding to keys
Select or Download Code
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!!
        regards
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://935305]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (18)
As of 2014-07-31 18:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (250 votes), past polls