Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:37:50+00:00 2026-06-13T04:37:50+00:00

Is there a way to do very quick sort in perl? Like I have

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:37:51+00:00Added an answer on June 13, 2026 at 4:37 am

    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:

    my @ordered_keys = sort { $a cmp $b } keys %hash;
    

    However, if you wanted to deal with the values in that way, you could do this:

    my @ordered_values = @hash{ sort { $a cmp $b } keys %hash };
    

    This uses a “hash slice”.

    But in this fashion, you could do the following:

    foreach my $value ( @hash{ sort { $a cmp $b } keys %hash } ) { 
        # key? What key?
        do_something_with_hash_value( $value );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very theoretical question: Is there a way to ban the use
I'm using GMP to calculate very large factorials (e.g. 234234!). Is there any way
There must a be a (very) quick and efficient way to get only elements
My question is very simple: is there any way to (programmatically, technically, or manually)
There is this way, of course: OuterClass.this . But that's very clumsy. Ideally, there'd
I'm very new to Oracle and was wondering if there's a way either through
To me they are very similar structures. I was hoping there was a way
I'm very new to Python and I'm sure there is a much easier way
I'm not very good at regex but maybe there's a simple way to achieve
is there any way to overload the dot-operator . We would like to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.