note
vek
<p>If you <code>use</code> a module, Perl deals with it at compile time. If you <code>require</code> a module, Perl deals with it at run time.</p>
<p>I typically like to <code>use</code> a module because it allows me to check everything via a <code>perl -c someprog.pl</code> after I've finished coding. It I used <code>require</code> instead, I wouldn't find out that something was wrong until I ran the program for the first time. YMMV, just my own personal preference.</p>
<p><code>require</code> is handy though if your program needs to do something based on whether you have a module installed on your system. You can test for this at runtime.</p>
<code>
#!/usr/bin/perl -w
use strict;
# do we have FOO::Bar on this system?
eval { require FOO::Bar };
if ($@) {
# FOO::Bar not installed
} else {
# FOO::Bar installed
}
</code>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-119620">
--
<a href="http://vek.perlmonk.org">vek</a>
--
</div></div>
368279
368308