Is there something wrong with the use that is required after printing starts?

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 something wrong with using the request after launching the output, or should everything be at the top of the script?

+2
perl
Feb 01 2018-10-01
source share
2 answers

I do not think that something is wrong with this.

But if you want or need more consistency in your scripts, you can rewrite the code in the required script as a subroutine. For example:

 ##### old page.pl ###### print "This is the body.<P>\n"; 1; ##### old cgi script ##### print "Content-type: text/html\n\n"; print "<html><head></head><body>\n"; require "page.pl"; 




 ##### new page.pl ###### sub page_body { print "This is the body.<P>\n"; } 1; ##### new cgi script ##### require "page.pl"; # now at the top of script print "Content-type: text/html\n\n"; print "<html><head></head><body>\n"; &page_body; 
+4
Feb 01 '10 at 18:10
source share
— -

No, it is not necessary that all require are at the top. Although, if require fails, your HTML will already be submitted halfway. :-P

+3
Feb 01 2018-10-0118
source share