Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by Eily (Monsignor)
on Oct 10, 2013 at 15:45 UTC ( [id://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.

Replies are listed 'Best First'.
Re^2: Help! Stuck on methods to count file size.
by marinersk (Priest) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1057753]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-19 20:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found