in reply to Constructing HTML tables with CGI.pm
The first problem is that you can't embed for loops inside function calls inside a print statement. However, Perl nicely deals with this using map. The second problem is that if you pass your TD wrapped data to Tr() as an anonymous array (ie. wrapped in []) as you have shown, CGI.pm will wrap each of the TD's in a seperate TR, which is probably not want you want. This may get started.
#!perl -slw use strict; use CGI; use CGI::Pretty; sub cgiOut { my (%host) = @_; my $q = new CGI; print $q->header( "text/plain" ), $q->start_html( -title=>"Apache Stats for \$hostname", -bgcolor=>"#ffffff"), $q->h2( "Apache Stats for \$hostname" ), $q->hr, $q->table( { -border=>"1", -width=>"100%" }, map{ $q->Tr( $q->td($_) , $q->td($host{$_}) ) } sort keys %host ); print $q->end_html; } my %host= ( foo=>100, bar=>200,, baz=>300 ); cgiOut %host;
Oh. I noticed a third problem too, it's spelt border not broder :)
|
|---|