in reply to Subroutine reference in @INC

Whenever you find a need to do something tricky, there are two things you need to do. First, step back and ask yourself if, in solving your problem, you solution creates more potential problems. Remember, simple is better. Why do you want to load a module from a zip file? You're simply going to slow things down and unless you have some serious space problems, I seriously doubt that this solution will show great benefit. Further, by playing around with @INC, you can easily create a maintenance nightmare for someone else later down the road.

If, after the first step you realize that you really have a need for this, figure out a way to do this that makes it clear to the programmer that something unusual is going on so they have a chance to follow what's going on. For example, if I see the following at the top of some code, I'd have a pretty clear idea that I need to dig deeper:

use Archive::Module qw/ Some::Big::Module /;

Then, in Archive::Module, you can stuff your real code and you won't need to play with @INC and possibly confuse the heck out of the poor programmer who has to maintain your code.

Incidentally, I'd love to see your code when you put it together.

Cheers,
Ovid

Update: After reading the response by Dominus, I feel less confident about use Archive::Module.... I wasn't aware that adding code refs to @INC was documented. I don't think I gave a bad answer, though, as it could potentially prove to be a very useful module.

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.