in reply to print content in cgi and html

I agree that the best way is to use the CGI module from CPAN. However if you only want your code to look tidy quickly, there are many ways -

Method 1 - Using qq{ ... }
print qq{Content-type: text/html <html><head>.....</head> <body bgcolor="white"> ..... </body> ..... </html> };
Method 2 - Using HEREDOC
print <<HTML Content-type: text/html <html><head>.....</head> <body bgcolor="white"> ..... </body> ..... $variable_text </html> HTML
Note that you can get rid of the \n from the end of every line, and you can embed variables in them too.

Replies are listed 'Best First'.
Re: Re: print content in cgi and html
by Anonymous Monk on Sep 26, 2003 at 14:23 UTC
    I have conditions in my html cgi output. How would I handle that?
    if($condition) { print <<HTML Content-type: text/html <html><head>.....</head> <body bgcolor="white"> if($variable == 1) { print $anotherVariable; } </body> </html> HTML }
      Use multi HERE Documents like:

      if ($condition) { print <<HTML Content-type: text/html <html><head>.....</head> <body bgcolor="white"> ... blah blah HTML if ($variable == 1) { print $anotherVariable; } print <<HTML ... blah blah </body></html> HTML }

      Or as I mentioned before use HTML::Template, it can handle all that for you too... go on try it, you know you want to. ;)