Thank you so much to everyone that contributed ideas to my question. Your input has been very valuable! Here's my solution (it's not the tightest code, but it gets the job done)
#!/usr/local/bin/perl5 -wT
print "Content-type: text/html\n\n";
$debug = 0; # Set 1 to enable debug; set to 0 to disable.
use Date::Calc qw( Date_to_Days );
@Months = ('1','2','3','4','5','6','7','8','9','10','11','12');
($Month_Day,$Month,$Year) = (localtime)[3,4,5];
$Year += 1900;
$date = Date_to_Days($Year,$Month,$Month_Day);
Debug (" Current date is: $date <br>");
open(HANDLE,"../script_integration_data/script_integration_records");
while (<HANDLE>) {
@temp1 = split(/:/);
$domain = unpack ("A4", $temp1[40]);
if (($domain eq "BBA") && ($temp1[36] eq "In Production") && ($temp
+1[38] != "-") && ($temp1[38] != "--")) {
$script_date = Date_to_Days($temp1[31],$temp1[30],$temp1[29]);
Debug ("$temp1[31],$temp1[30],$temp1[29]");
$diff_date = abs ($date - $script_date);
Debug ("script date is: $script_date and difference is: $diff_d
+ate days. and $temp1[0]<br>");
# If diff_date is greater than 90 days we exectue.
if (($diff_date <= 90) && ($diff_date > -$diff_date)) {
$sum += $temp1[38];
$count++;
}
}
}
close(HANDLE);
$average = $sum / $count;
if ($average >= 44) {
print sprintf "<blink><font color=\"#FF0000\">%.f days</font></blin
+k>", $average;
} elsif (($average >= 11) && ($average <= 44)) {
print sprintf "<font color=\"#FFFF00\">%.f days</font>", $averag
+e;
} elsif ($average <= 10) {
print sprintf "<font color=\"#669900\">%.f days</font>", $average;
}
sub Debug {
if ( $debug ) {
my $msg = shift;
print $msg, "\n";
}
}
# EOF
-Gus
I just changed up a bit by taking the absolute value instead of just getting the difference...I almost missed that, but luckily I caught it in time. Time to brush up on that 'ole math. :-)
-
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.