1. I read somewhere that print statments are very slow, so I originally wanted to keep everything to one print at the very end. Would it be better to store all the variables globally or pass them to the subroutine that prints? (Let's just say we have 10-15 small variables or so.)As other people have said further down, who cares? Printing isn't slow, compared to everything else you're doing in a CGI script. If you really want speed up, convert it to a mod_perl environment, and add a templating system like HTML::Template that can cache templates. Caches are extremely fast. Of course, if you want even faster you probably set up another server/apache process doing dedicated caching, but that's beyond the scope of this node.
2. A little thing that's been bugging me: In a subroutine that takes parameters, is it faster to use shift() or $_0?This is silly to worry about. You should use shift so you can name your variables.
3. Normally, I use CGI.pm for my scripts, but it's a pretty large module and I'm concerned about speed since I only use it for reading cookies and submitted data. Would it be faster to just assign all the values to a hash at the beginning, and is there anything I might miss that CGI.pm would have caught?This is actually a somewhat fair question, CGI.pm is horribly bloated and slow, but fortunately several alternatives, such as CGI::Simple, which is about twice as fast (I think), and CGI::Lite, which is even faster than CGI::Simple exist. There are benchmarks on this site if you really care.
In reply to Re: Some questions about CGI and optimizing Perl
by BUU
in thread Some questions about CGI and optimizing Perl
by Cap'n Steve
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |