Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Help! Stuck on methods to count file size.

by Eily (Hermit)
on Oct 10, 2013 at 15:45 UTC ( #1057753=note: print w/ replies, xml ) Need Help??


in reply to Help! Stuck on methods to count file size.

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.


Comment on Re: Help! Stuck on methods to count file size.
Select or Download Code
Re^2: Help! Stuck on methods to count file size.
by marinersk (Chaplain) on Oct 10, 2013 at 16:35 UTC
    I will waste one element on my XP-per-node score denominator to say this, because I truly enjoyed the raw truth of it.

    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.

    OMG LOL !!!

Re^2: Help! Stuck on methods to count file size.
by Anonymous Monk on Oct 11, 2013 at 03:15 UTC
    Thank you for your reminding! It's very valuable!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1057753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2014-07-13 22:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (252 votes), past polls