while (%mthlens=<$fh>) runs only once, no matter how many lines are in your file, because <$fh> is run in list context (ie: it is affected to a hash, which can take several elements in, so all the lines are returned at once to fill those elements).

chomp, as a lot of other Perl function do, works by default on $_ if no argument is supplied. But since you don't affect anything to $_, it's quite useless. If you wanted your lines to be in $_ you could have written either while ($_=<$fh>) or while(<$fh>), and then you would have read line by line. You might want to use another variable instead though, with while (my $line = <$fh>) and then chomp $line.

while ( my ($Janlen,$length,$filename) = each %lengths) doesn't make much sense, each returns a list of two values, so if you affect it to three scalars, the third one will be undef.

Actually running your code under strict and warnings, and not just putting those line at the last moment to avoid being told to do so would help you avoid most of the mistakes you make instead of waiting for an answer here.


In reply to Re: Help! Stuck on methods to count file size. by Eily
in thread Help! Stuck on methods to count file size. 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.