Is there a way to do very quick sort in perl? Like I have a very large hash, probably with 100 million keys there. It is very inefficient to do foreach my $x (sort {$a cmp $b} keys %myhash){DO SOMETHING} when I test. Wondering if I can first copy out all keys to a array and use a quick sort to it.
Is there a way to do very quick sort in perl? Like I have
Share
You wouldn’t want to put the hash in a list context, because you do not want the values sorted with the keys. Instead, yes you want to sort the keys:
However, if you wanted to deal with the values in that way, you could do this:
This uses a “hash slice”.
But in this fashion, you could do the following: