in reply to Can perl modules be compiled?

Perl script can be compiled but that will usually lead to slower loading.

Take a look at AutoLoader and AutoSplit instead.

Replies are listed 'Best First'.
Re^2: Can perl modules be compiled?
by davebaker (Pilgrim) on Feb 26, 2007 at 14:52 UTC
    Hello! I wonder what's the best practice to deal with this limitation described in the AutoLoader documentation:

    Package lexicals declared with my in the main block of a package using AutoLoader will not be visible to auto-loaded subroutines, due to the fact that the given scope ends at the __END__ marker. A module using such variables as package globals will not work properly under the AutoLoader.

    The vars pragma (see "vars" in perlmod) may be used in such situations as an alternative to explicitly qualifying all globals with the package namespace. Variables pre-declared with this pragma will be visible to any autoloaded routines (but will not be invisible outside the package, unfortunately).

    The vars pragma sounds risky, but I thought that using "my" in the main block as globals for subroutines was standard practice. Am I wrong (perhaps there should be no such "globals" for subroutines, and everything needed to produce the subroutine's result should come in as a parameter; or use "our")?