in reply to Re: MSIE Favorite Start Page
in thread MSIE Favorite Start Page

I absolutely agree with you that most CGI projects aught to use CGI.pm, however this is not a cgi script. Proper HTML formatting is only one of the benefits of CGI, but it also comes at a cost: you have to know what you are writing early. Example, the same table as before, but with CGI:
my @table; while( @linkURL ) { my $linkLeft = td( a( { -href => pop( @linkURL ) } pop( @linkName +) ) ); my $linkRight = @linkURL ? td( a( { -href => pop( @linkURL ) } pop +( @linkName ) ) ) : " "; push @table, TR( $linkLeft, $linkRight ); } print FILE table( {}, @table ) or die "Print Failed, $!, $^E\n\t ";
Yeah, that's more Perl-ish, but its also less straightforward. Why should I have to build up the entire table in memory before I can print it to the file?

So I didn't use CGI. I did think about using CGI, I do know how to use CGI, and I made the decision that I didn't want or need CGI for this 10 minute project. Now, if I were runing a web server on my desktop and wanted this page generated on the fly (which would be cool) I would use CGI to generate the header() info for me. I would also use the start_html() and end_html() functions, but I still wouldn't use the table functions.

Thank you, by the way, for bringing up the subject. Too many people forget that CGI is just another tool in the tool box. Sometimes it isn't the right solution, sometimes its not the right tool.

PS: Thanks for the tip on <center> being deprecated. I did not know that. According to the w3c spec for HTML 4.01 I should have used <DIV align=center>.

Replies are listed 'Best First'.
Re: Re: Re: MSIE Favorite Start Page
by ichimunki (Priest) on Jan 13, 2001 at 04:34 UTC
    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.