Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: using a variable with require

by haukex (Archbishop)
on Jun 22, 2022 at 06:36 UTC ( [id://11144938]=note: print w/replies, xml ) Need Help??


in reply to using a variable with require

See the core module Module::Load (there are others, like Module::Runtime, but this one is core), plus the \&{'subname'} symbolic reference syntax which is allowed even under strict. However, if $name is user input, this is still a security risk!

use warnings; use strict; use Module::Load qw/load/; my $name = 'SomeModule'; load $name; (\&{$name.'::somesub'})->();

Replies are listed 'Best First'.
Re^2: using a variable with require
by geoffleach (Scribe) on Jun 22, 2022 at 13:20 UTC
    Hmmm ... from the doc, I would not have guessed it, but it appears that Module::Load is exactly what I need. Many thanks.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 12:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found