First of all, you have a mistake in your code. The first line in your loop should be:

my @split_hit_total = split(/\s+/, $_);

since $_ is your loop variable here, not $hit_total. (use strict is good for catching things like that, BTW!)

That said, to answer your question: repurpose your HoA so that it stores (for each $protein_ac) the lowest encountered iEvalue along with its corresponding range, rather than all ranges. E.g. instead of pushing the range, do this:

if(!defined($HoA_total_hits{$protein_ac}) || $HoA_total_hits{$protei +n_ac}->{'iEvalue'} > $iEvalue) { $HoA_total_hits{$protein_ac}->{'iEvalue'} = $iEvalue; $HoA_total_hits{$protein_ac}->{'range_b'} = $range_b; }

Untested in the absence of example data... and I've not had my morning brew yet, so apologies if this is obvious rubbish.

(Side note -- I turned your HoA into a HoH here, but didn't change the name. I'd advise against putting the type of a variable in its name anyway.)

EDIT: using the sample data from Re^2: How can I add an entry in a has of arrays based on numeric comparison?, here's what Data::Dumper has to say about the contents of $HoA_total_hits after running this:

$VAR1 = { 'I5EU07' => { 'range_b' => '232-824', 'iEvalue' => '3.4e-137' } };

Does that look right?


In reply to Re: How can I add an entry in a has of arrays based on numeric comparison? by AppleFritter
in thread How can I add an entry in a has of arrays based on numeric comparison? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.