blink has asked for the wisdom of the Perl Monks concerning the following question:

I have the following subroutine:
# print include files for SSI sub printIncludes { for my $incHandle ( keys %anchors ) { for my $status ( keys %{ $anchors{$incHandle} } ) { print $incHandle "@{ $anchors{$incHandle}{$status} }\n"; } } }

which creates a table like this. I'm stuck trying to modify this sub to print one column for each distinct color(status) found in %anchors.

%anchors gets populated like this:

# Hash of colors my %colors = ( active => "#005154", failed => "#ff0000", queued => "#622188", partial => "#ffb90f", success => "#00ff00" ); # Hash of titles my %titles = ( active => "Active Jobs", failed => "Failed Jobs", queued => "Queued Jobs", partial => "Partially Successful Jobs", success => "Successful Jobs" ); $incString = "<tr><td align=\"center\"><a href=\"\#$class\.$titles{$status}\"><font + color=\"$colors{$status}\">$class</a></font></td></tr>"; push ( @{ $anchors{$incHandle}{$status} }, $incString );

As per usual, any assistance is greatly appreciated. ~ ~ ~

Replies are listed 'Best First'.
Re: Dynamic HTML table Creation
by BrowserUk (Patriarch) on Aug 15, 2002 at 04:12 UTC

    Something like (untested):

    # print include files for SSI sub printIncludes { print '<tr>'; for my $incHandle ( keys %anchors ) { my $lastStatus; for my $status ( keys %{ $anchors{$incHandle} } ) { print $incHandle "@{ $anchors{$incHandle}{$status} }\n"; print '</tr><tr>'if defined $lastStatus && $status ne $la +stStatus; $lastStatus = $status; } } print '</tr>'; }

    And remove the <tr></tr> from the anchor strings as:

    $incString = "<td align=\"center\"><a href=\"\#$class\.$titles{$status +}\"><font color=\"$colors{$status}\">$class</a></font></td>";

    What's this about a "crooked mitre"? I'm good at woodwork!
Re: Dynamic HTML table Creation
by DamnDirtyApe (Curate) on Aug 15, 2002 at 03:44 UTC

    Could you please post a sample of the data that you're using to build the table? (ie. the stuff that appears in the table you cited.)

    Thanks,


    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche
      It would be a little difficult, since data is gathered from the system itself, rather than flat files, db, etc. I suppose that I could dump one of the main datastructures, if you would like?