in reply to Should I just print my own HTTP headers?

I'm sure you've heard this a million times: CGI.pm is big and I don't want to use it.

Yup, and every time I hear it it sounds pretty foolish. CGI.pm may be big, but it uses Autoloader extensively to avoid memory bloat. And if you've got a modern Perl you don't even have to download it, it's a standard module! So just use it already! In the time it took you to ask this question you could be done already, not to mention dealing with parsing parameters.

-sam

  • Comment on Re: Should I just print my own HTTP headers?

Replies are listed 'Best First'.
Re^2: Should I just print my own HTTP headers?
by Cap'n Steve (Friar) on Apr 05, 2007 at 22:45 UTC
    True, but even ignoring the Autoloader stuff, it's still 800+ lines of code that has to be loaded to accomplish something that would probably take me around 10.
      You make it sound like you're going to load those lines of code with your bare hands in an ice storm. Trust me, this is not the bottleneck you're looking for! I've profiled a lot of slow web-apps in my day and I've never once seen a CGI.pm method in the top 10.

      -sam

        And uphill both ways! But according to this test, printing one header by hand is 11331% more efficient than using CGI to do it. Did I miss something?
        #!/usr/bin/perl use warnings; use strict; use Benchmark ':all'; open OUT, '> nul' or die $!; cmpthese(100000, { 'cgi' => 'use CGI ":cgi";my $cgi = new CGI;print OUT $cgi->header( +"text/html");', 'plain' => 'print OUT "Content-type: text/html\n\n";' });
      You might be better off using CGI.pm to get started, and then later on if loading the 800+ lines appears to be a problem, replace it with your 10 lines. That way you only have to write one line now: "use CGI;", and you'll be able to look at the HTML source being produced so that you know exactly what you need to replace it with, if you still want to.