in reply to Re: Constructing HTML tables with CGI.pm
in thread Constructing HTML tables with CGI.pm

Even after I adding those tags, I couldnt get output in a table format

Modified Code

#!/usr/local/bin/perl -w use strict; use CGI; my %host=( 'camel', 'flea', 'frog', 'green'); cgiout(); sub cgiout { my $q= new CGI; print $q->header; print $q->start_html; my $tablecontent=[$q->th(['key', 'value'])]; for (sort keys %host) { push @$tablecontent, $q->td([ $_, $host{$_} ]) ; } print $q->table( { border => 1, -width => '100%'}, $q->Tr( $tablecontent), ); print $q->end_html; }

Output

Content-Type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <table width="100%" border="1"><tr><th>key</th> <th>value</th></tr> <t +r><td>camel</td> <td>flea</td></tr> <tr><td>frog</td> <td>green</td>< +/tr></table> </body> </html>

Replies are listed 'Best First'.
Re^3: Constructing HTML tables with CGI.pm
by choroba (Cardinal) on Sep 19, 2014 at 14:41 UTC
    Just to make sure, do you run the script on a web server and view the result in a browser?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: Constructing HTML tables with CGI.pm
by Anonymous Monk on Sep 20, 2014 at 05:12 UTC

    Even after I adding those tags, I couldnt get output in a table format

    The output you show is "html tables" -- what were you expecting?
    key value
    camel flea
    frog green