Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hi Experts,

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 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 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, 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..

#! /path/to/perl -wT # THis is the login validation script # Import CGI module use strict; use CGI qw(:all delete_all escapeHTML); use common_subs; use "path/to/other/modules/"; # Create a new CGI object my $query = new CGI; # Create query objects to retrieve input my $username=$query->param('user'); my $passwd=$query->param('password'); my $next_page = ""; my $loginOK = check_login($username,$passwd); print $query->header; print $query->start_html(-title=>'Validate Login',-bgcolor=>'white', - +style=>{src=>'/IMG_PATH/templatestyles.css'}); # This is the common header defined in common_subs and # I use that in all scripts &display_header("Check Login"); if ($loginOK == 1) { print $query->b("Login successful! Loading next page....\n"); print $query->start_form(-name=>'data',-action=>$next_page); print $query->end_form(); print $query->script("setTimeout(\";\",5000);"); } else{ print $query->font({-color=>"red"},$query->p("Login Failed!!!") +, $query->br(), $query->p("Please go back to login screen and enter c +orrect userid and password!!!")); ... etc... ... } # This is the common footer defined in common_subs and # I use that in all scripts &display_footer; print $query->end_html();

and the common subroutine is defined as follows in

use CGI qw/:standard :html3 :all/; use strict; sub check_login{ .... } sub display_header { my $disp_text=$_[0]; # Note that I have to create a new CGI object here in the sub my $query = new CGI; print $query->center; print $query->table( { -border=>0}, Tr([ td( {-align=>"center" },[ $query->img({-align=>"center", +-src=>"logo.gif ", -border=>0 }), $query->font({-size= +>'4'},$query->b( $disp_text)), ]), ]), ); } sub display_footer{ ... ... }

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 , 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 Is it fair to say that if I use HTML::Template, my scripts would be organized better than just using Again, is there any impact on the performance in terms of using HTML::Template rather than 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

In reply to Clarifications in subroutines,, HTML::Template and performance by sara2005

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2021-05-17 16:30 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (158 votes). Check out past polls.