tags:

views:

59

answers:

2

Example:

my $page = $args{'p'};
exit 1 if $page =~ /[^\d\w]/;

print "Content-Type: text/html\n\n";

print "<html><head></head><body>";

require "$page.pl";

somefunc();

print "</body></html>";

Is there anything wrong with using the require after the output has started or should all requires be at the top of the script?

+3  A: 

No, there's no need for all requires to be at the top. Though, if the require fails, your HTML would be halfway sent already. :-P

Chris Jester-Young
+4  A: 
mobrule
Indeed, one of the first steps in refactoring old monolithic cgi scripts (with inlined HTML, no functions etc) is to divide functionality into separate files and using `require`.
Ether