in reply to Constructing HTML tables with CGI.pm

Seems like a missing header (not mentioning start_html). See CGI for details.
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
  • Comment on Re: Constructing HTML tables with CGI.pm

Replies are listed 'Best First'.
Re^2: Constructing HTML tables with CGI.pm
by sravs448 (Acolyte) on Sep 19, 2014 at 14:19 UTC
    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>
      Just to make sure, do you run the script on a web server and view the result in a browser?
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      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