Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Constructing HTML tables with CGI.pm

by kabel (Chaplain)
on Mar 28, 2003 at 07:28 UTC ( #246416=note: print w/ replies, xml ) Need Help??


in reply to Constructing HTML tables with CGI.pm

you want Tr () to output your hash. so, each key/value pair inside the hash must be encapsulated inside a td () - the loop to use therefore is "map", not "for".

for is only used for the sideeffects of the corresponding block that is applied to each of the elements of the list. especially the for does not return anything meaningful.

the map takes a list, and returns a list - and that is what you want. you specify the transform of each element in the list in the map block. consider this:

use strict; use warnings; use CGI qw/:standard/; my %hosts = ('a' .. 'z'); cgiOut (); sub cgiOut { 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%" }, $q->Tr({}, [map { td([$_, $hosts{$_}]) } sort keys %hosts])), $q->end_html; }

HTH

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2016-07-28 14:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?


















    Results (255 votes). Check out past polls.