I said I was ambivalent about CGI due to the nature of the script, and I know why after trying to rewrite it-- there's no lovely solution when loops are involved. I've banged my head up against it because I apparently enjoy the pain. So here's how I solved it with sub refs. (I left the HTML in 3.2 because I got lazy after all this).
use CGI qw(:standard -nodebug);
... same code through open () ...
my $table_cell = sub {
print "table_cell called\n";
(@linkName)
? return td( {-align => "left"},
a( {-href => pop( @linkURL ) }, pop( @linkName ) )
)
: return td();
};
my $table_rows = sub {
print "table_rows called\n";
my $rows;
foreach (@linkName) {
$rows .= Tr( &$table_cell, &$table_cell );
}
return $rows;
};
print FILE (
start_html( -title => "Favorite Links",
-bgcolor => "#000000",
-link => "$lcolor",
-alink => "$lcolor",
-vlink => "$lcolor"),
table( { -align => "center" }, &$table_rows ),
end_html()
) or die "write error: $!\n";
... and close ...
For the record (on Win95), your original code died on a filename with the (r) mark in it. And this was after I had commented out the System Error line (line 12) because it kept tripping there-- would you explain what that line does for us less advanced types? Once those two issues were sidestepped, it worked, rendering the very handy page.
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.