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.


In reply to Re: Basic arithmetic functions by aufrank
in thread Basic arithmetic functions by KristiePi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.