RE: how to efficiently sort hash without using keys()



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
.



Relevant Pages

  • Re: Legal version?
    ... > Classic; German version). ... It's also talking about many keys on CD. ... Thomas ... Prev by Date: ...
    (rec.games.computer.stars)
  • Re: Genuine 2 player Interface 2 Joystick games
    ... Sometimes you can Define keys and then choose for Player 1 keys 1-5 and ... Regards ... Thomas ... Prev by Date: ...
    (comp.sys.sinclair)
  • Re: TS sucht falschen Lizenzserver
    ... Hallo Thomas, ... Aus den notwendigen Registry-Keys ein .adm-File generieren ... Alternativ wäre es aber viel effektiver, ... finden (nach löschen der o.a. Keys) die TS die Lizenzdienste ...
    (microsoft.public.de.german.windows.terminaldienste)
  • Re: Common Task
    ... > consequents for not having these two keys? ... >> Saved Views is how you have a folder setup, for example, you may have ... Prev by Date: ...
    (microsoft.public.windowsxp.general)
  • Re: The Vegas Code - Part 33 (The Last One)
    ... I fell asleep once and woke up with my keyboard imprinted on my face and drool in between the keys. ... Good job, Thomas... ...
    (alt.vacation.las-vegas)