If you use a module, Perl deals with it at compile time. If you require a module, Perl deals with it at run time.
I typically like to use a module because it allows me to check everything via a perl -c someprog.pl after I've finished coding. It I used require 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.
require 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.
#!/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 }
In reply to Re^3: Program structure: subs vs modules vs Selfloader
by vek
in thread Program structure: subs vs modules vs Selfloader
by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |