blink has asked for the wisdom of the Perl Monks concerning the following question:
What I would like to do is, foreach "my $class ( sort keys %classHash )", place a colorzed (based upon status) link to the actual stats on the report. In other words, at the place in the code that I have commented:################################# # open report files for printing # yes, @fhandles is populated # yes, I am using strict # yes, I am using perl -w # = ) my $filepath = "/usr/openv/scripts"; open $fhandles[0], ">>$filepath/nt.html" or die "cannot open $filepath/nt.html for writing: $!\n"; open $fhandles[1], ">>$filepath/mail.html" or die "cannot open $filepath/mail.html for writing: $!\n"; open $fhandles[2], ">>$filepath/unix.html" or die "cannot open $filepath/unix.html for writing: $!\n"; ##### code................... # Print HTML-header the hard way... foreach (@fhandles) { my $team; $outhandle = $_; if ( $outhandle =~ /NT/ ) { $team = "Windows Infrastructure Team"; } if ( $outhandle =~ /MAIL/ ) { $team = "Mail Team"; } if ( $outhandle =~ /UNIX/ ) { $team = "UNIX Infrastructure Team"; } print $outhandle <<EOC <html> <head> <title>[Backup report] $humanstart - $humanstop</title> </head> <body bgcolor="#ffffff"> <h2 align="left">Daily Backup Report: $team</h2> <h3 align="left">From $humanstart to $humanstop</h3> EOC } ## ## ## HERES WHERE I WANT TO PLACE MY LIST OF HTML ANCHORS ## ## foreach my $class ( sort keys %classHash ) { foreach my $status ( sort keys %{$classHash{$class}} ) { if ( $classname{$class} eq "NT" ) { $outhandle = *NTOUT; } if ( $classname{$class} eq "UNIX" ) { $outhandle = *UNIXOUT; } if ( $classname{$class} eq "MAIL" ) { $outhandle = *MAILOUT; } if ($status eq "success") { print $outhandle <<SUC; <table border=1 width="100%"> <tr> <td colspan="12" align="left" valign="center" bgcolor="#33cc33"> <b><font size="+2">$class: Successful Jobs</b></font> </td> </tr> SUC } elsif ($status eq "partial" ) { print $outhandle <<PAR; <table border=1 width="100%" > <tr> <td colspan="12" align="left" valign="center" bgcolor="#ffcc00"> <b><font size="+2">$class: Partially Successful Jobs</b></font> </td> </tr> PAR } elsif ( $status eq "failed" ) { print $outhandle <<FAIL; <table border=1 width="100%"> <tr> <td colspan="12" align="left" valign="center" bgcolor="#ff0000"> <b><font size="+2">$class: Failed Jobs</b></font> </td> </tr> FAIL } elsif ( $status eq "active" ) { print $outhandle <<ACT; <table border=1 width="100%"> <tr> <td colspan="12" align="left" valign="center" bgcolor="#c1ffc1"> <b><font size="+2">$class: Active Jobs</b></font> </td> </tr> ACT } elsif ( $status eq "queued" ) { print $outhandle <<QUE; <table border=1 width="100%"> <tr> <td colspan="12" align="left" valign="center" bgcolor="#b23aee"> <b><font size="+2">$class: Queued Jobs</b></font> </td> </tr> QUE } print $outhandle <<EOC; <tr> <th align="center">Hostname</th> <th align="center">Job-ID</th> <th align="center">Schedule</th> <th align="center">Status</th> <th align="center">Server</th> <th align="center">Files</th> <th align="center">Tries</th> <th align="center">Start </th> <th align="center">End </th> <th align="center">Duration</th> <th align="center">Mbytes</th> <th align="center">Speed</th> </tr> EOC foreach my $id ( @{$classHash{$class}->{$status}} ) { my $thisjob = $alljobs{$id}; my $MB = $thisjob->{kbytes} / 1000; &print_report_line( $thisjob->{client}, $thisjob->{jobid}, $thisjob->{schedule}, $thisjob->{status}, $thisjob->{server}, $thisjob->{files}, $thisjob->{trycount}, &epoch($thisjob->{started}), &epoch($thisjob->{ended}), $thisjob->{elapsed}, #&beautify_number($thisjob->{kbytes}), &round($MB), ($thisjob->{elapsed} gt 0 ? int(($thisjob->{kbytes}/$thisjob->{elapsed})*1 +00)/100 : "0.00")); if ($status eq "failed" ) { &print_errortext_line +($thisjob->{status}); } } print $outhandle "</table><br>\n"; } }
failed class 1 failed class 2 successful class 1
... and so on, WITHOUT having to reiterate through the two hashes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing to specific position in a file
by graff (Chancellor) on Aug 05, 2002 at 03:11 UTC | |
by blink (Scribe) on Aug 06, 2002 at 01:59 UTC |