Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Basic arithmetic functions

by aufrank (Pilgrim)
on Aug 08, 2002 at 17:30 UTC ( #188656=note: print w/replies, xml ) Need Help??

in reply to Basic arithmetic functions

you could try something like:

#! /opt/local/bin/perl -w # I recommend the strict pragma if you are new to perl use strict; # you could get the data you provided into an array in any # number of ways. my @data = ("1234-5678 12 .345678", "1234-5678 90 .123456"); my $sum; foreach (@data) { # puts each piece of information into its own variable # in case you need to use them for something. # you could push them into arrays to keep track of them my ($user_id, $proc_id, $time) = split(); # adds the time from the current line to the running # total of time values $sum += $time; } # divides the total times by the total number of times # (the index of the last element in the array + 1) my $average = $sum/($#data + 1); print $average;

that is probably much longer than it needs to be, but it worked when I tested it on your data.

good luck!

update: bah! not only did Dimmesdale beat me to it, he had comments too! added comments.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2022-12-02 08:56 GMT
Find Nodes?
    Voting Booth?