Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Beginner question - understanind a loop with a file handle

by Generoso (Parson)
on Oct 15, 2010 at 01:28 UTC ( #865378=note: print w/replies, xml ) Need Help??


in reply to Beginner question - understanind a loop with a file handle

# Read each line of file supposing a number per line # while <FILE> { # # the += operator will add each number read to #the accumulated # $total += $_; # # $_ contains the line just read of FILE # ++ will increment 1 for each line giving a total # count of lines at the end of the loop # $count++; } # # at the end of the loop you have total = sum of lines # and count how many lines where read # my $average = $total/$count; # # the formula above calculates the average

Now Can you see the code? Any line that starts with # is a comment.

Replies are listed 'Best First'.
Re^2: Beginner question - understanind a loop with a file handle
by GrandFather (Sage) on Oct 16, 2010 at 06:52 UTC

    Damn, I'm sure there is supposed to be code in there some where, but for the life of me I can't see it!

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://865378]
help
Chatterbox?
[Discipulus]: really?
[Corion]: :-D
[Discipulus]: i was kidding.. and i was kidded:perl -lne " if (length $_ > $l){$l=length $_;$w=$_}}{print qq($w $l\n)" linux.words

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-10-18 08:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (243 votes). Check out past polls.

    Notices?