Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Basic arithmetic functions

by dimmesdale (Friar)
on Aug 08, 2002 at 17:22 UTC ( [id://188653]=note: print w/replies, xml ) Need Help??


in reply to Basic arithmetic functions

Check out split, it can be real helpful at times.

# real important! use strict; use warnings; # this is the file where the data is my $file = 'path_to_file'; # these are some useful variables my $sum = 0; my $lines = 0; my $avgerage; # open file open(FH, $file) or die "File $file failed to open:"; #read file in line by line while(<FH>) { # get the third column and add it to $sum $sum += (split /\s+/, $_)[2]; # update $lines $lines++; } # now, to get the average, all you do is say $average = $sum/$lines;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-03-28 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found