What should you name after printing HTML from a Perl CGI script? I saw empty return , exit return , and in some cases nothing at all. Does it matter?
#!perl print "Content-type: text/html\n\n"; print <<'END_HTML'; <!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"> <head> <title>Hello world!</title> </head> <body> <h1>Hello world!</h1> </body> </html> END_HTML # do anything else here? # return; # exit;
Update
Suppose you have some tests in which you print HTML that is not at the very end of the file. In this case, it is more clear to call exit or return to visually show that the script should complete at this time? I know this is not the best way to write this - please just take it at face value for the sake of the question.
#!perl use CGI; my $q = CGI->new(); my $action = $q->param('action'); my $html_start = "Content-type: text/html\n\n"; $html_start .= <<'END_HTML'; <!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"> <head> <title>Hello world!</title> </head> <body> END_HTML my $html_end = <<'END_HTML'; </body> </html> END_HTML if ($action eq 'foo') { print $html_start; print '<p>foo</p>'; print $html_end;
source share