Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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?

As a GENERAL rule, yes, your code is improved by taking "display-only" aspects out of the Perl code proper. Much like modules, it makes the code easier to follow and read, and thus debug. By keeping your HTML as mostly-pure HTML, it also makes it easier to debug and validate it, as well.

In terms of speed, switching to HTML::Template will make a mark. There are ways around that; Template Toolkit (sort of HTML::Template's big brother) will compile it's templates for added speed, and I suspect H::T has similar capacity. And indeed, a quick search on Google shows HTML::Template::Compiled and HTML::Template::JIT. Another cheap/easy way to help with CGI apps (this one more memory than speed) is to, when you're running with templating full-time, use a smaller version of the CGI module, like CGI::Simple, which takes out the HTML-generating portions of the full-bore CGI, leaving the bits that are for parameter-processing and header-generating.

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

Frankly, with CGI, I worry far more about readability and maintaining of code. You pay such a cost in basic CGI overhead that shaving time for your CGI code is almost not worth it in many cases; if you want to optimize, do it after you convert to a mod_perl or similar setup, if you need to. However, staying with CGI-based solutions, I'd recommend you look into CGI::Application, which is a nice module for running multiple CGI "scripts" under one umbrella. If you're willing to make a bigger leap; I think you'll find a web framework like Catalyst to be a powerful ally; it has authorization routines as an easy-to-use module, for example.

How easy (or difficult) it is to move to mod_perl or any other better technology?

The more you code in a nice, easy-to-debug style, the better off you are with mod_perl. You might want to start with Apache::PerlRun, using the CGI conversion guide on the mod_perl site to sort out how to make this happen. Some of this will depend on if you're using mod_perl version 1 or 2, of course.

If mod_perl is not your speed, there are other solutions, such as FastCGI.

I hope this helps.

----Asim, known to some as Woodrow.


In reply to Re: Clarifications in subroutines, CGI.pm, HTML::Template and performance by Asim
in thread Clarifications in subroutines, CGI.pm, HTML::Template and performance by sara2005

Title:
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 How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found