Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Loading a module at runtime...

by andrewc (Acolyte)
on Apr 08, 2003 at 08:51 UTC ( [id://248860]=note: print w/replies, xml ) Need Help??


in reply to Loading a module at runtime...

I'm sure others are already pointing this out, but the second eval line uses double quotes, so an interpolation is being done before eval "" even sees it.

My preferred form is:
if (defined $module) { # Detaint $module =~ m/^(My_Safe_Namespace(?:\:\:\w+)*)$/ or die "Unsafe module name: $module\n"; $module = $1; eval "use $1;"; die if $@; # Call 'run' as a method to avoid eval-string $module->run(); }
Eval-string is generally a bad idea for security reasons, assuming you're relying on data external to the program. This is just a way of minimising its use.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-04-24 09:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found