Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: use depending on environment

by Xaositect (Friar)
on Jun 22, 2005 at 15:57 UTC ( [id://469068]=note: print w/replies, xml ) Need Help??


in reply to use depending on environment

Using a begin block is preferrable if you can get away with it, but if you can't know whether or not you want to load a module at compile-time, try using 'require' instead of 'use'. 'require' will load the module at run-time. ( 'use' is equivilant to BEGIN { require MODULE; } )

In general, 'use' is preferable because it gives the compiler more information about the symbols in your namespace. For example, where you might have done

use Data::Dumper; print Dumper $foo;
You can't just substitute require because then the compiler won't know where the "Dumper" function comes from. Instead you have to do something like
require Data::Dumper; print Data::Dumper::Dumper($foo);


Xaositect - Whitepages.com

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-03-28 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found