Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (7)
    As of 2021-05-07 13:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Perl 7 will be out ...





      Results (91 votes). Check out past polls.

      Notices?