<br><br><div class="gmail_quote">On Tue, Dec 8, 2009 at 3:53 PM, Joshua Johnson <span dir="ltr">&lt;<a href="mailto:joshpauljohnson@gmail.com">joshpauljohnson@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello all!<br>
<br>
Is there a way to test if a perl module is loaded? I&#39;m working on a<br>
small project where I load some modules dynamically as part of a<br>
configuration and then &quot;use&quot; them at that time. I don&#39;t get any errors<br>
but I just feel dirty loading a module that may have already been<br>
loaded. So, if at the top of the file I do:<br>
<br>
use Whatever::Project::MyStuff;<br>
<br>
Can I find out later if Whatever::Project::MyStuff is already loaded?<br>
I suppose it may not matter or have any kind of performance impact but<br>
now I&#39;m just curious to know if it can be done.<br>
<br></blockquote><div><br></div><div>I think &quot;require&quot; will do just fine, with minimum performance impact in this case.</div><div><br></div><div>But it can be done by looking at the corresponding entry for the module in %INC array. So after</div>
<div> </div><div><br></div><div>      use Whatever::Project::MyStuff;</div><div><br></div><div>or simply</div><div><br></div><div>       require Whatever::Project::MyStuff;</div><div><br></div><div>you must find a true value at </div>
<div><br></div><div>        $INC{&#39;Whatever/Project/MyStuff.pm&#39;}</div><div><br></div><div>So you have to transform the module name into a file name (for example, like UNIVERSAL::require does).</div><div><br></div><div>
You can read the docs of %INC with a new version of perldoc with</div><div><br></div><div>      $ perldoc -v &#39;%INC&#39;</div><div><br></div><div>or just look for the corresponding section of &quot;perlvar.pod&quot; if your perldoc is not so new.</div>
<div><br></div><div><br></div><div>Cheers,</div><div>Adriano Ferreira</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Thanks,<br>
Josh J<br>
_______________________________________________<br>
Buffalo Perl Mongers Homepage<br>
<a href="http://buffalo.pm.org" target="_blank">http://buffalo.pm.org</a><br>
<br>
Buffalo-pm mailing list<br>
<a href="mailto:Buffalo-pm@pm.org">Buffalo-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/buffalo-pm" target="_blank">http://mail.pm.org/mailman/listinfo/buffalo-pm</a><br>
</blockquote></div><br>