Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Constructing HTML tables with CGI.pm

by BrowserUk (Patriarch)
on Mar 28, 2003 at 07:25 UTC ( [id://246415]=note: print w/replies, xml ) Need Help??


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 :)


Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://246415]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (2)
As of 2024-04-20 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found