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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|