So you don't want to sort the array, you want to find the max value in it. So write a subroutine to find the max value in your array and call that (just like chromatic suggested!)
use strict; # ALWAYS!!!!!! # MaxElementInArray( @array ) sub MaxElementInArray { my $max = shift; my $next; $max = $next > $max ? $next : $max while $next = shift; return $max; } # MaxElementInArrayRef( \@array ) sub MaxElementInArrayRef { my $array_ref = shift; my $index = $#$array_ref; my $max = $$array_ref[$index]; $max = $$array_ref[$index] > $max ? $$array_ref[$index] : $max while --$index >= $[; return $max; }
Update: While examining your code in response to your statement below, I've noticed quite a few style issues: You don't use strict, you are not using CGI.pm, and you are not using subroutines to improve the readability (and maintainability) of your code. I strongly suggest you look into these things. As for your issue of trying to use a number before you have calculated it... this reveals a failure to plan before coding. Now I suspect you will need to re-write much of this code just to get things in a causal order.

In reply to RE: RE: Re: Breaking a Loop by Adam
in thread Breaking a Loop 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.