Re: how to efficiently sort hash without using keys()
- From: konfera@xxxxxx (Ing. Branislav Gerzo)
- Date: Wed, 25 May 2005 12:39:52 +0200
Paul Johnson [PJ], on Wednesday, May 25, 2005 at 12:21 (+0200) made
these points:
>> @array = sort @array;
PJ> Using each will also affect the iterator.
hm.
PJ> I suggest changing the the previous code so it doesn't care what happens
PJ> to the iterator. For example:
PJ> my @keys = keys %hash;
PJ> for (@keys)
PJ> {
PJ> some_sub_that_messes_with_the_iterator();
PJ> }
yes, I actually change that, and using it like this:
my $hr = $get->fetchall_hashref('id');
$hr->{cattable_index} = [ reverse sort {
$hr->{$a}{counter} <=> $hr->{$b}{counter} } keys %{$hr} ];
$hr->{oses} = get_oses($hr);
$hr->{categories} = get_categories($hr);
$hr->{categories_index} = [ sort { $a <=> $b } keys %{$hr->{categories}} ];
for my $os ( @{$hr->{oses}} ) {
....
hashes, hashes, hashes ! :)
--
How do you protect mail on web? I use http://www.2pu.net
["Whenever I see a dalmation I say, `What number are you?'" - s.w.]
.
- References:
- how to efficiently sort hash without using keys()
- From: Ing. Branislav Gerzo
- Re: how to efficiently sort hash without using keys()
- From: Paul Johnson
- how to efficiently sort hash without using keys()
- Prev by Date: perl 'advancing' variable facility..
- Next by Date: Re: perl 'advancing' variable facility..
- Previous by thread: Re: how to efficiently sort hash without using keys()
- Next by thread: RE: how to efficiently sort hash without using keys()
- Index(es):
Relevant Pages
|