I'm not sure what you mean by
calculate, whether you want to average them all or something else. However, one way to gather them all up so you can do what you want with them is this.
# We already have a filehandle open for reading. Read
# file line by line, putting data into a hash table.
#
our %averages = ();
while(<IN>)
{
# Pick out the "average" lines with a regular
# expression using () round brackets to remember
# the "average1 or 2" (in $1) and the value ($2).
#
next unless /^(average\d+):\s+(\d+\.\d+)$/;
push @{$averages{$1}}, $2;
}
you end up with a hash table with keys "average1" and "average2" and the values being a list of the relevant values so that doing
print $averages{average1}->[0], "\n";
print $averages{average2}->[1], "\n";
Would produce
3.2
5.0
I hope this helps.
Cheers,
JohnGG
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.