Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Use with variable

by edan (Curate)
on Sep 08, 2004 at 13:34 UTC ( [id://389355]=note: print w/replies, xml ) Need Help??


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

my $module = "CGI"; $module->require; $module->import;

Can't locate object method "require" via package "CGI" (perhaps you forgot to load "CGI"?) at t.pl line 2.
--
edan

Replies are listed 'Best First'.
Re^3: Use with variable
by Corion (Patriarch) on Sep 08, 2004 at 13:39 UTC

    That's what I get for not testing my stuff :-((

    So it seems the only actually working way is the ugly way of converting the module name to the file name and then requiring that file :

    my $module = "CGI"; my $filename = $module; $filename =~ s!::!/!g; $filename .= ".pm"; require $filename or die "$module did not return a true value"; $module->import;

    (this time tested it ...)

      Do you have something against eval? I think that's the most straightforward solution...

      --
      edan

        I try to avoid string-eval wherever I can, because I don't like the security implications of it. Of course, it's unlikely that a module name like CGI; qx(rm -rf /)

        can be injected, but with my solution that gets avoided completely. Of course, this is most likely total overkill, as in most cases, modules are loaded dynamically upon program startup depending on the OS.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found