Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^3: Use with variable

by Aristotle (Chancellor)
on Sep 08, 2004 at 22:11 UTC ( [id://389494]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Use with variable
in thread Use with variable

Actually, you don't need to interpolate the variable, and it's much safer not to:

my $module = "Digest::MD5"; eval 'use $module'; # note single quotes

That's because use $var actually works. You just have to somehow populate $var before the compile-time effect of use takes place. A BEGIN block lets you do that. Silly example:

my $module; BEGIN { $module = "Digest::MD5"; } use $module;

Note that the snippets of course aren't equivalent — the first loads the module at runtime, the second loads it at compile time.

Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found