Monkeys,
I'm trying to write a CGI that generates a dynamic table within another table also generated via CGI. I wrote a small test script to display what I want and it is posted below.
#!/usr/bin/perl -w
use strict;
use CGI;
my $q = new CGI;
print $q->header( -type => "text/html"),
$q->start_html,
$q->start_table(),
$q->Tr(
$q->td("Cell1"),
$q->td("Cell2")
),
$q->Tr(
$q->td("Cell3"),
$q->td(nested())
),
$q->end_table,
$q->end_html;
sub nested
{
$q->start_table(),
$q->Tr(
$q->td("Cell4"),
$q->td("Cell5")
),
$q->Tr(
$q->td("Cell6"),
$q->td("Cell7")
),
$q->end_table,
}
This produces:
When I attempt to change the code so the second table is created by a simple for loop like to the following:
#!/usr/bin/perl -w
use strict;
use CGI;
my $q = new CGI;
print $q->header( -type => "text/html"),
$q->start_html,
$q->start_table(),
$q->Tr(
$q->td("Cell1"),
$q->td("Cell2")
),
$q->Tr(
$q->td("Cell3"),
$q->td(nested())
),
$q->end_table,
$q->end_html;
sub nested
{
$q->start_table();
for (my $x = 4; $x < 8; $x++)
{
print $q->Tr(
$q->td("cell ". $x),
$q->td("cell ". $x+1)
);
$x++;
}
print $q->end_table;
}
I get:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<HTML><HEAD><TITLE>Untitled Document</TITLE>
</HEAD><BODY><TABLE><TR><TD>Cell1</TD> <TD>Cell2</TD></TR><TR><TD>Cell
+3</TD> <TD>1</TD></TR></TABLE></BODY></HTML>
printed to the browser window. I'm curious as to what would cause this. I have a feeling I'm just overlooking something but as of yet I have not found said "thing."
As a side note: The code I am working on is
Here but isn't having the same problem...instead the second table is printed first, and then the first table is printed beneath the second. If you're up for charity work you could take a look at that one as well. The code for it is posted
Here
System Notes Just to make sure all needed info is given this is using 5.005_03 on Linux Redhat 6.2 and tested under Apache. If more info is needed I'll post it here if it is asked for
Regards,
Macphisto
Everyone has their demons....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.