In both your programs you have:
while ($k>=2) { if ($k==1) {last;}
so the condition for entering the while loop is $k>=2 but inside the loop itself someone might guess that you're checking if $k==1 and it may not become clear that there's a decrement towards the while block end, for readability and logic flow it would be better if this is written down towards the end of the while block after $k=$k-1; for example, but again, since you don't want $k==1 to be considered the loop would exit automatically if you only write while($k>2) without the need to check if $k has reached to 1.

compare:

while($k>2){ $k=$k-1; print "$k\n"; } #and while($k>=2){ $k=$k-1; #last if $k==1; print "$k\n"; }

$total=0; is used only once, what is it intended to contain?, where @first is coming from in  $ntotal+=$_ for @first;
Another major point, using strictures can save you a lot of nasty repercussions arising from undiscovered bugs and for readability you may want to pick up an indentation that is intuitive or use Perltidy, here is an initial tutorial.


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: help finding mean, numbers above and below mean from an exponential distribution by biohisham
in thread help finding mean, numbers above and below mean from an exponential distribution by kaupifalco

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.