print a hash ordered by value

Discussion in 'Perl Misc' started by Yiping Zhan, Jun 20, 2004.

  1. Yiping Zhan

    Yiping Zhan Guest

    What is a good way of getting a printed output like:

    d 7
    b 6
    a 3
    c 1

    if I have a hash like:

    %h = qw(a 3 b 6 c 1 d 7);

    Thank you!

    -- Newbie
     
    Yiping Zhan, Jun 20, 2004
    #1
    1. Advertising

  2. Yiping Zhan

    Anno Siegel Guest

    Yiping Zhan <> wrote in comp.lang.perl.misc:
    > What is a good way of getting a printed output like:
    >
    > d 7
    > b 6
    > a 3
    > c 1
    >
    > if I have a hash like:
    >
    > %h = qw(a 3 b 6 c 1 d 7);


    That's a frequently asked question. You can look up the answer through
    perldoc -q 'sort a hash'.

    Anno
     
    Anno Siegel, Jun 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    590
    red floyd
    Nov 10, 2011
  2. robertj

    ordered/sorted hash

    robertj, Dec 8, 2005, in forum: Ruby
    Replies:
    19
    Views:
    225
    William James
    Dec 11, 2005
  3. Hal Fulton

    A use case for an ordered hash

    Hal Fulton, Aug 13, 2006, in forum: Ruby
    Replies:
    89
    Views:
    684
    Haoqi Haoqi
    May 5, 2007
  4. Devi Web Development

    Ordered Hash Usefulness

    Devi Web Development, Nov 13, 2007, in forum: Ruby
    Replies:
    18
    Views:
    291
    Ralph Siegler
    Nov 26, 2007
  5. DL

    Ordered list inside ordered list

    DL, Nov 9, 2009, in forum: Javascript
    Replies:
    6
    Views:
    355
    Dr J R Stockton
    Nov 21, 2009
Loading...

Share This Page