in reply to Require Load Times

Probably because most of CGI subroutines are autoloaded. If you look into sources of CGI.pm you can find a code that looks like:
%SUBS = ( ... ... ... 'some_sub1' => <<'END_OF_FUNC', sub some_sub1 { ... ... } END_OF_FUNC 'some_sub2' => <<'END_OF_FUNC', sub some_sub2 { ... ... } END_OF_FUNC ... ... ... )
As you can see defenitions of subroutines are put into a hash as strings. When Perl parses such code it does it very quickly since it doesn't have to parse actual subroutine code.

CGI.pm uses AUTOLOAD to detect undefined subroutine calls and to evaluate subroutines code on fly when they are used.

Update: You can use autoloading techiques yourself for your modules. Probably you don't need to roll your own code for autoloading like CGI.pm does. Use one of these modules: AutoLoader, SelfLoader and autouse.

--
Ilya Martynov (http://martynov.org/)

Replies are listed 'Best First'.
Re: Re: Require Load Times
by ehdonhon (Curate) on Dec 30, 2001 at 10:26 UTC

    That's kind of an interesting way of doing it. I wonder how CGI.pm's method of doing things compares to using autoloader? Typically, whenever I create a module, I prefer to just use h2xs -X modulename to set up my Makefile.pl and stub module. That stub module is already set up to use Autoloader. Would I be better off speed wise if I tried to implement my modules the same way that CGI.pm does?

    In my particular case, most of my work is done with mod_perl, so I'm guessing that using Autoloader is probably better from a memory efficency perspective. Then again, I suppose CGI.pm is typically used in mod_perl as well. Can anybody shed some light on this subject?

      The short answer is that it depends. The long answer is that shared memory is very very good in mod_perl situations. Some people go as far as to force CGI to compile all of the common subroutines when the server starts -- that way, they'll be available to any child that needs them in a shared memory page. If they had to be autoloaded occasionally during a request, each child would have its own copy in a fresh memory page.

      The mod_perl guide has lots of suggestions and equations.