Perl: the Markov chain saw | |
PerlMonks |
Re^3: Testing for a module's presenceby sgifford (Prior) |
on Feb 07, 2005 at 04:45 UTC ( [id://428568]=note: print w/replies, xml ) | Need Help?? |
The thing I don't like about searching @INC is that it's re-implementing a part of Perl based on how it works right now. A future version of Perl could use a different scheme for locating libraries. For example, it could add a new type of arch directory, hash the directories to avoid too many modules in the same directory, add a new .pmz type for compressed modules on disk-poor systems, or load code across the network. A user could even provide their own copy of the lib module and/or the require function to implement those sorts of things right now.
In the face of possible changes to the module search algorithm, actually asking Perl to find the library and say whether it worked or not will always work, while re-implementing the library search yourself will only work for as long as nothing changes. Using a module designed to do this, as others have suggested here, is a good compromise. As for the cross-platform concerns, I have used fork on ActiveState Windows; it seems like a lot would break without a working copy of this function. And POSIX::_exit seems to avoid your other concerns. Also, to clarify, I don't think using fork will be particularly fast; just faster than using system, which was my original proposal.
In Section
Seekers of Perl Wisdom
|
|