Re: how to sort hash by value, where value is a valid date
- From: Brian Wakem <no@xxxxxxxxx>
- Date: Tue, 31 May 2005 20:05:47 +0100
perl_help_needed wrote:
> Hi all,
> I want to sort a hash by its vlaue in perl. Value is a valid date.
> example:
> key value
> 48487 05/05/18
> 52327 05/05/23
> 64998 05/05/24
> 44147 05/05/18
> ........etc..
> here value can be any valid date in the format yy/mm/dd.
> Could anyone help me out with this one please!!
> Thanks..
You cannot actually sort a hash, but your can access its contents in
specified order in a foreach loop, like this:-
foreach (sort { $hash{$a} cmp $hash{$b} } keys %hash) {
print "Date:$hash{$_}\tKey:$_\n";
}
--
Brian Wakem
.
- References:
- how to sort hash by value, where value is a valid date
- From: perl_help_needed
- how to sort hash by value, where value is a valid date
- Prev by Date: Re: how to test if an element belongs to an array or hash
- Next by Date: Re: numbers and strings and regex?
- Previous by thread: how to sort hash by value, where value is a valid date
- Next by thread: Re: how to sort hash by value, where value is a valid date
- Index(es):
Relevant Pages
|
|