sorting a hash / 2008-06-01
- From: "dn.perl@xxxxxxxxx" <dn.perl@xxxxxxxxx>
- Date: Fri, 30 May 2008 00:21:42 -0700 (PDT)
I want to sort a hash. The hash contains a list of cities and their
temperature and I want the 4 cities with max temp. The problem is that
the city-names are one extra level deep with the state-name coming in-
between. I wondered whether I should build the hash differently. A
different format would be: state_city, with the underbar separating
the state and the city.
$hash{Calif_Cupertino}{max_temp} = 38 ;
instead of
$hash{Calif}{Cupertino}{max_temp} = 38 ;
my %hash = () ;
$hash{Calif}{San Jose}{max_temp} = 84 ;
$hash{Calif}{San Fran}{max_temp} = 94 ;
$hash{Calif}{Cupertino}{max_temp} = 38 ;
$hash{Calif}{Fremont}{max_temp} = 66 ;
$hash{Texas}{Dallas}{max_temp} = 72 ;
$hash{Texas}{Austin}{max_temp} = 96 ;
$hash{Texas}{Fort Worth}{max_temp} = 62 ;
$hash{Mass}{Boston}{max_temp} = 96 ;
$hash{Mass}{Framingham}{max_temp} = 55 ;
$hash{Mass}{Worcester}{max_temp} = 55 ;
How do I sort this hash, please?
Thanks in advance.
.
- Follow-Ups:
- OT: SI units (was sorting a hash / 2008-06-01)
- From: sheinrich
- Re: sorting a hash / 2008-06-01
- From: Gunnar Hjalmarsson
- Re: sorting a hash / 2008-06-01
- From: A. Sinan Unur
- Re: sorting a hash / 2008-06-01
- From: John W. Krahn
- OT: SI units (was sorting a hash / 2008-06-01)
- Prev by Date: FAQ 6.16 How do I efficiently match many regular expressions at once?
- Next by Date: Re: How to make input user and password in perl script started on web?
- Previous by thread: FAQ 6.16 How do I efficiently match many regular expressions at once?
- Next by thread: Re: sorting a hash / 2008-06-01
- Index(es):
Relevant Pages
|
|