Perhaps something like this would work?
use strict;
use Statistics::Descriptive;
my $uwlRatio = 15;
my $poStat = Statistics::Descriptive::Sparse->new();
my $frStat = Statistics::Descriptive::Sparse->new();
while(my $line = <DATA>)
{
chomp $line;
my ($poData, $frData) = split( m/\s/, $line);
$poStat->add_data($poData);
$frStat->add_data($frData);
if($poStat->mean() > 0)
{
my $pofrRatioMean = $poStat->mean() / $frStat->mean();
if($pofrRatioMean > $uwlRatio)
{
print "DANGER WILL ROBINSON! PO/FR ratio out of spec!\n";
}
else
{
print "PO/Fr ratio within spec: $pofrRatioMean\n";
}
}
else
{
print "not enough data to calculate ratio.\n";
}
}
__DATA__
0 0
0 0
150 10
0 0
200 40
210 40
220 40
220 30
220 20
220 10
220 05
220 01
220 100
220 100
2200 100
2200 2
2200 2
2200 1
With output like this:
$perl example.pl
not enough data to calculate ratio.
not enough data to calculate ratio.
PO/Fr ratio within spec: 15
PO/Fr ratio within spec: 15
PO/Fr ratio within spec: 7
PO/Fr ratio within spec: 6.22222222222222
PO/Fr ratio within spec: 6
PO/Fr ratio within spec: 6.25
PO/Fr ratio within spec: 6.77777777777778
PO/Fr ratio within spec: 7.57894736842105
PO/Fr ratio within spec: 8.51282051282051
PO/Fr ratio within spec: 9.59183673469388
PO/Fr ratio within spec: 7.09459459459459
PO/Fr ratio within spec: 5.85858585858586
PO/Fr ratio within spec: 9.11290322580645
PO/Fr ratio within spec: 13.4939759036145
DANGER WILL ROBINSON! PO/FR ratio out of spec!
DANGER WILL ROBINSON! PO/FR ratio out of spec!
-
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.
|