Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

(Ovid) Re: require and use

by Ovid (Cardinal)
on Feb 12, 2002 at 20:34 UTC ( #144981=note: print w/replies, xml ) Need Help??


in reply to require and use

use happens at compile time (and calls the package's import method, if any) and require doesn't happen until run time.

"use"ing a module will tell you at compile time if you have any compilation problems, but you won't find out with require until you actually hit the "require" statement while the code is running. use is more or less equivalent to the following:

BEGIN { require Foo::Bar; Foo::Bar->import; }

Typically, you want to use modules and not require them, but if you have a module that you don't want to load unless needed (perhaps in an error routine), then require it:

sub error_handling { my $data = shift; require Data::Dumper; die Data::Dumper::Dumper $data; } # or sub error_handling { my $data = shift; require Data::Dumper; Data::Dumper->import; die Dumper $data; }

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2019-11-19 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (94 votes). Check out past polls.

    Notices?