Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Constructing HTML tables with

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

in reply to Constructing HTML tables with

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, 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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2021-04-23 10:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found