Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Program structure: subs vs modules vs Selfloader

by vek (Prior)
on Jun 20, 2004 at 18:31 UTC ( #368314=note: print w/replies, xml ) Need Help??


in reply to Re^2: Program structure: subs vs modules vs Selfloader
in thread Program structure: subs vs modules vs Selfloader

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 }
-- vek --

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://368314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2020-12-02 16:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (43 votes). Check out past polls.

    Notices?