rsennat has asked for the wisdom of the Perl Monks concerning the following question:

hi all,

i have a perl class, class_1.pm in a separate folder and use that in the main.cgi as shown below.
#!/usr/local/bin/perl5.8 -w -I../myclass use CGI; use HTML::Template; use CGI::Carp 'fatalsToBrowser'; use class_1;
this perl/cgi script runs very slower but when i comment out "use class1", it runs faster.
fyi, im not using any methods from that class, just for testing.

what makes the script to run slowly???

thanks
rsennat

Replies are listed 'Best First'.
Re: including a class makes the perl/cgi script run slower
by Fletch (Bishop) on Nov 30, 2005 at 17:50 UTC

    Sunspots. Or evil gnomes. One of the two. Probably gnomes.

    Without seeing the code there's any number of things that it could be doing, from calling sleep( 5+rand(5) ) to traversing the current working directory and posting a copy of your secret muffin recipe to USENET. When you use module; the code is pulled in and any statements outside subroutine declarations get executed (remember use is effectively inside a BEGIN { } block), so there's no telling what the problem is without more info.

    (And another thing: modules starting with lower case names are bad ideas as by convention those are "reserved" for pragmatic modules for Perl's use (e.g. strict or base); granted this particular name isn't likely to cause a conflict but it's bad style.)

    Update: Changed phrasing in the parenthetical comment on naming to make it read more good.

Re: including a class makes the perl/cgi script run slower
by Joost (Canon) on Nov 30, 2005 at 17:54 UTC
    It's slower because the class_1.pm file gets loaded, compiled and run.

    A use statement is just a fancy include: it loads a perl file, compiles it and runs the code. Perl doesn't know or care that you don't use any methods in that file.

    I'd guess that your class_1.pm file is either very large or it contains directly executable code (outside of the method declarations) that takes some time to run.

Re: including a class makes the perl/cgi script run slower
by belg4mit (Prior) on Nov 30, 2005 at 18:33 UTC
    Do you do anything careless like use English or $& and friends (which use English does, actually)?

    --
    In Bob We Trust, All Others Bring Data.