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 6716683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:45:46+00:00 2026-05-26T08:45:46+00:00

Thanks in advance for the help. I have a array called %pepHash with 174

  • 0

Thanks in advance for the help.

I have a array called %pepHash with 174 ‘counts’ and multiple ‘peptides’ in each $count.
Here’s a snippet of the hash:

Count: 39   Peptide: 0  Score: 55.03    MR: 1792.3206
Count: 39   Peptide: 1  Score: 75.22    MR: 1792.6158
Count: 39   Peptide: 2  Score: 62.63    MR: 1972.7156
Count: 39   Peptide: 3  Score: 49.95    MR: 2365.2174
Count: 40   Peptide: 0  Score: 46.38    MR: 1256.4437
Count: 40   Peptide: 1  Score: 71.07    MR: 1950.1644
Count: 40   Peptide: 2  Score: 71.77    MR: 2492.9394
Count: 40   Peptide: 3  Score: 67.28    MR: 2493.0154

Firstly, I’m not very good with data structures, so any better advice on multi-d hashes would be nice.

Count: 40   Peptide: 1  Score: 71.07    MR: 1950.1644 

is accessed by $pepHash[$count][$pepCount]{$PEP_SCORE} or {$PEP_MR}, and in this case it’s obviously $pepHash[40][1]{$PEP_SCORE}.
I want to sort all of %pepHash by its scores in descending order or create a new sorted hash so the list becomes:

Count: 39   Peptide: 0  Score: 75.22    MR: 1792.6158  
Count: 39   Peptide: 1  Score: 62.63    MR: 1972.7156 
Count: 39   Peptide: 2  Score: 55.03    MR: 1792.3206 
Count: 39   Peptide: 3  Score: 49.95    MR: 2365.2174
Count: 40   Peptide: 0  Score: 71.77    MR: 2492.9394 
Count: 40   Peptide: 1  Score: 71.07    MR: 1950.1644
Count: 40   Peptide: 2  Score: 67.28    MR: 2493.0154
Count: 40   Peptide: 3  Score: 46.38    MR: 1256.4437

Notice the updated $pepCount values. I have this loop which could be of use:

   for ($count = 0; $count < $total; $count++) {
      for ($pepCount = 0; $pepCount < $pepTotal[$count]; $pepCount++) {
      }
   }

I was also messing with this to no avail cause I’m a noob:

foreach $key (sort {$pepHash{$b} <=> $pepHash{$a}} keys(%pepHash)) {
   #CONFUSED
}

EDIT: This helped me a lot: http://www.stathis.co.uk/computers/perl-sort-tutorial

  • 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-05-26T08:45:47+00:00Added an answer on May 26, 2026 at 8:45 am

    To store such data structures you may use hash of hashes. Here’s example:

    my %pepHash;
    
    $pepHash{someKey} = { Score => 100, Count => 42 };
    $pepHash{someOtherKey} = { Score => 200, Count => 43 };
    # ...
    

    And then sort this hash:

    foreach $key (sort {$pepHash{$b}->{Score} <=> $pepHash{$a}->{Score}} keys(%pepHash)) {
       my $data = $pepHash{$key};
       print "$key: Score - $data->{Score}, Count - $data->{Score}\n";
    }
    

    You may also want to read Perl documentation to feel yourself better with Perl data structures and perldoc -f sort to learn more about sorting in Perl.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using c# .net. Thanks in advance for any help. I have searched
Thanks in advance... i have a string array which i want to set in
thanks in advance for your help. I am wondering if there is a (design)
Thanks in advance for your help experts. I want to be able to copy
First hi and thanks in advance in ASP.NET : assume that i have a
I have an array, say int a[]={2,0,1,0,1,1,0,2,1,1,1,0,1,0,1}; I need to append each of the
I have the following 3 x 3 x 3 numpy array called a (the
I have an array filled with dictionaries. Each dictionary have strings like title, info
I have a custom class in Obj-C called RouteManager which contains an array of
and thanks in advance for the help. Background - I am writing a PHP

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.