Hello Everyone,
I am new to PERL and programming in general and I am about to lose my mind. I have been working on this program for about 2 weeks and I still can't figure out what I am doing wrong. The main problem lies within the second WHILE loop(I think), I can't seem to figure out how to get it to reference the stuff in the rest of the script,it is supposed to take the value defined and print a color to the HTLM file depending on the length of time that has passed. It is probably something very simple that I am doing wrong, help at all will be appreciated. Sorry that this is such a mess but I really don't know what I am doing.
use Time::local;
$ccdrive = $ENV{CC_DEFAULT_DRIVE};
$file = "whatever";
$upsitesynckey = "SyncState X";
$downsitesynckey = "SyncState Y";
$upsitereplicakey = "Replica for X";
$downsitereplicakey = "Replica for Y";
my @newtime;
my $htmlpath='synccheck.htm';
my $logfile='synccheck.log';
my $maxtime;
my %month = (Jan => 0, Feb => 1, Mar => 2, Apr => 3, May => 4,
Jun => 5, Jul => 6, Aug => 7, Sep => 8, Oct => 9,
Nov => 10, Dec => 11);
#Define some colors...
my $GRN="#00FF00";
my $YEL="#FFFF00";
my $RED="#FF0000";
my $GRY="#808080";
my $curcolor=$GRN;
my %rephash;
open(TFILE2,">$htmlpath") || die "Can't open $htmlpath";
# Print the html header section.
print TFILE2 <<WEB_PAGE;
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-12
+52">
<title>SyncCheck</title>
</head>
<body background="PrairieWind.bmp" bgcolor="#000000" text="#FFFFFF" li
+nk="#FFFF00" vlink="#FFFF00">
<p> </p>
<p align="center"><font face="Americana" size="5">Sync Check
Summary</font></p>
<p align="center"><font face="Americana" size="5">/font></p>
<p align="left"> </p>
WEB_PAGE
# Handle the "Last Update"
my $time=localtime(time);
print TFILE2 "<p align=\"center\"><font face=\"Americana\" size=\"4\">
+Last update: $time</font></p><br>\n";
open (FILE, "$file") || die "Can't open $file";
$tmp=<FILE>;
foreach(split(/\t/,$tmp)){
push(@hashkeys, $_);
}
while (<FILE>) {
$tmp=$_;
@config=split(/\t/,$tmp);
$idx=0;
#Combine the two arrays into a hash. Taking the long way around, h
+ere.
foreach(@config){
$vobhash{$hashkeys[$idx]}=$_;
$idx++;
}
#Clear out the arrays.
@config=("");
# Get a more accurate vob tag.
$name=$hash{"Tag"};
#If the syncstate of a site has an X or "EXPORT", Add its replica
+to the list.
if(uc($vobhash{$upsitesynckey}) eq "X" || uc($hash{$upsitesynckey}
+) eq "EXPORT"){ push(@replicas, $hash{$upsitereplicakey}); push(@vobs
+, $vobname); }
if(uc($vobhash{$downsitesynckey}) eq "X" || uc($vobhash{$downsites
+ynckey}) eq "EXPORT"){ push(@replicas, $vobhash{$downsitereplicakey})
+; push(@vobs, $vobname); }
%vobhash = ("");
}
close (FILE);
$idx=0;
foreach $replica (@replicas) {
$cmd="cleartool describe replica:$replica\@\\$vobs[$idx]";
$time=`$cmd`;
$time =~ /last_export = /g;
$time=substr($time, pos($time), length($time)-pos($time));
$idx++;
@timelocal = localtime(time);
$day=substr($time, 0, 2);
$mon=substr($time, 3, 3);
$year="20".substr($time, 7, 2);
$hour=substr($time, 10, 2);
$min=substr($time, 13, 2);
$sec=substr($time, 16, 2);
# Convert the month abbreviation to a number (0-11). Use separate
+variable.
$mon = $month{$mon};
@newtime=($sec, $min, $hour, $day, $mon, $year, undef, undef, unde
+f);
#print "$mon\n";
$x=Time::Local::timelocal(@timelocal);
$y=Time::Local::timelocal(@newtime);
$z=$x-$y;
#print "$x $y $z\n";
my $durhours=int($z/3600);
$z-=($durhours*3600);
my $durmins=int($z/60);
$z-=($durmins*60);
my $dursecs=$z;
#$rephash{$replica}=$durhours;
#$rephash=("$replica"=>"$durhours","durhours"=>"$curcolor");
if ($durhours < 3) {
$curcolor = "$GRN";
}
if ($durhours >= 3 && $maxtime < 7 ) {
$curcolor = "$YEL";
}
if ($durhours > 7 ) {
$curcolor = "$RED";
}
if ($durhours > $maxtime) {
$maxtime = $durhours;
}
%rephash=($replica=>"$curcolor");
#print "$rephash{$replica}\n";
if ($replica =~ /ABC/g) {
push (@ABC, $replica);
}
if ($replica =~ /DEF/g || $replica =~ /whatever/g) {
push (@DEF, $replica);
}
}
$idx=0;
$ref1 = @ABC;
$ref2 = @DEF;
print TFILE2 "<table width=\"75%\" border=\"1\">";
#
while ($idx < @ABC || $idx < @DEF) {
print TFILE2 " <tr>";
if ($idx1 <= $ref2) {
#chomp($DEF[$idx]);
#print TFILE2 "<font color=\"$rephash($DEF[$idx])\"><td>$vobs[
+$idx]</td>" ;
print TFILE2 "<font color=\$rephash{$replica}\> <td> $rephash{
+$replica} $DEF[$idx] </td>";
#print "%rephash{$DEF[$idx]}\n";
}
if ($idx1 <= $ref1) {
#chomp($ABC[$idx]);
#print TFILE2 "<font color=\"$rephash($ABC[$idx])\"> <td> $vob
+s[$idx] </td> ";
print TFILE2 "<font color=\"$rephash($ABC[$idx])\"><td> $AB
+C[$idx]  </td> ";
}
print TFILE2 "</tr>";
$idx++;
}
print TFILE2 "</table>";
Edit kudra,
2001-10-30
Changed title
-
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.