Locutus has asked for the wisdom of the Perl Monks concerning the following question:
Dear Fellow Monks,
please, have a look at the following quite minimalistic CGI program:
#!/usr/bin/perl use strict; use warnings; use CGI; my $cgi = new CGI; print_document_header(); print_document(); ###################################################################### sub print_document_header { ###################################################################### print $cgi->header( -type => 'text/html' ), "\n"; } ###################################################################### sub print_document { ###################################################################### print $cgi->start_html( -dtd => '-//W3C//DTD HTML 4.01 Transitional//EN', -title => 'Hello, world!', ), "\n", $cgi->p( 'Hello, world!' ), "\n", $cgi->end_html(); }
I have three questions regarding this program:
Why is it sufficient to pass $cgi only to the subroutine which calls $cgi->header and simply use the "global" $cgi in any other subroutine?###################################################################### sub print_document_header { ###################################################################### my $cgi = shift @_; print $cgi->header( -type => 'text/html' ), "\n"; }
Humble thanks for your adwise in advance!
|
|---|