I have been asked to add a colorized set of HTML anchors to the top of a report that I am generating. My problem is, that I'd like to do this without reiterating through a hash. Here's what I mean:
################################# # 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"; } }
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:

failed class 1 failed class 2 successful class 1

... and so on, WITHOUT having to reiterate through the two hashes.


In reply to Writing to specific position in a file by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.