|The stupid question is the question not asked|
Clarifications in subroutines, CGI.pm, HTML::Template and performanceby sara2005 (Scribe)
|on Jun 18, 2006 at 02:31 UTC||Need Help??|
sara2005 has asked for the wisdom of the Perl Monks concerning the following question:
First, sorry if I had asked too many questions but all seem related to me. I recently started with perl and was happily working with the CGI.pm module and some modules from CPAN to create my web app. When I had doubts, I started searching in the web and referred to CGI programming in Perl by Shishir & Scott, online docs, etc, but was not to able to answer some of the (basic!!) questions. Hence, I am here hoping to get some wisdom from the experts. Would appreciate your thoughts, comments on the following.
1) I am creating ~10 web-pages using CGI.pm. As I need common headers and footers for the page, I call a subroutine to do that, which is defined in a separate module (say, common_subs.pm). In the first few lines of each cgi script, I instruct to "use common_subs" and "use strict" but it looks like I have to create a new cgi object in the main program as well as the module (which has the common subs). Since I do that twice, would that have any impact on the performance? especially with medium duty scripts? (If I don't use "use strict",I just create a new CGI object in the main script and the code is working fine. anyway, I am going to use "use strict" in my code by default but would appreciate your reasoning)
Here is some portion of the code..
and the common subroutine is defined as follows in common_subs.pm:-
2) I have downloaded some modules from CPAN and installed them in a different path. I define it as "use /path/to/other/modules" at the top of each script and also set some standard environment variables. Can I define these in the common_subs.pm , which I call in all scripts? (the idea is to define common items in one file so that it would be easy for maintenance)
3) I read about the HTML::Template module after having started doing my scripts in CGI.pm. Is it fair to say that if I use HTML::Template, my scripts would be organized better than just using CGI.pm? Again, is there any impact on the performance in terms of using HTML::Template rather than CGI.pm alone?
4) I have a tendency to create separate cgi scripts for each task. i.e., I call separate scripts to check login, execute commands, read and display menus, etc.. etc.. Should I minimize the no of cgi programs (as I know that each invocation of cgi script has some overheads - I use Apache, no of max users at a given moment not to exceed 15) or it is ok to go ahead with my approach?
5) How easy (or difficult) it is to move to mod_perl or any other better technology? (there are some links I found in the search but they are fairly old !!!)
As always, I look for your valuable comments