http://qs321.pair.com?node_id=188656


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!
--au

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