RE: how to efficiently sort hash without using keys()
- From: t.baetzler@xxxxxxxxxx (Thomas Bätzler)
- Date: Wed, 25 May 2005 12:13:55 +0200
Ing. Branislav Gerzo <konfera@xxxxxx> asked:
> anyone has better idea how to sort hash by key without using
> keys() function? (I can't use it, it resets iterator...).
I don't understand the problem. Could you please give
an example where that would be a problem?
> my bruteforce looks:
>
> use strict;
> use warnings;
>
> my %hash = ( 1 => 'one',
> 2 => 'two',
> 3 => 'three'
> );
>
> my @array = ();
> while (my ($key, $value) = each(%hash)) {
> push @array, $key;
> }
> @array = sort @array;
I'm guessing here - are you looking for:
print join(', ', @hash{sort keys %hash} ) . "\n";
Or maybe http://search.cpan.org/~jgatcomb/Tie-Hash-Sorted-0.10/Sorted.pm ?
HTH,
Thomas
.
- Prev by Date: how to efficiently sort hash without using keys()
- Next by Date: Re: how to efficiently sort hash without using keys()
- Previous by thread: Re: how to efficiently sort hash without using keys()
- Next by thread: perl 'advancing' variable facility..
- Index(es):
Relevant Pages
|