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

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