in reply to Where and when you should place 'use module;'?

A use Module will cause the module to be loaded when the program starts, regardless of where in the script you put it (it gets run in a BEGIN block).

I personally think it makes more sense to put all your "use" statements at the start of your script, that way you can easily see what your dependencies are - no nasty surprises.


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re^2: Where and when you should place 'use module;'?
by davidrw (Prior) on Oct 12, 2005 at 12:59 UTC
    I also like to put all the "use" statements at the top, with one exception, and i believe this is what OP is looking for:
    use ModuleUsed::LoadedAt::CompileTime; sub sub1 { require Module1; # loaded at runtime ... } ...
    By using a require statement, the module will only be loaded at runtime of that line, which means IFF sub1() is called. The huge advantage here is that Module1 is only loaded into memory when (if ever) needed, which could be a big time/memory saver if it is a large module, especially if memory footprint is an issue.