Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: dynamic class names

by particle (Vicar)
on Jul 11, 2003 at 15:57 UTC ( [id://273432]=note: print w/replies, xml ) Need Help??


in reply to dynamic class names

from perldoc -f use:

use Module VERSION LIST use Module VERSION use Module LIST use Module use VERSION Imports some semantics into the current package from the n +amed module, generally by aliasing certain subroutine or variab +le names into your package. It is exactly equivalent to BEGIN { require Module; import Module LIST; } except that Module *must* be a bareword.

and from perldoc -f require:

If EXPR is a bareword, the require assumes a ".pm" extensi +on and replaces "::" with "/" in the filename for you, to make it + easy to load standard modules. This form of loading of modules +does not risk altering your namespace. In other words, if you try this: require Foo::Bar; # a splendid bareword The require function will actually look for the "Foo/Bar.p +m" file in the directories specified in the @INC array. But if you try this: $class = 'Foo::Bar'; require $class; # $class is not a bareword #or require "Foo::Bar"; # not a bareword because of t +he "" The require function will look for the "Foo::Bar" file in +the @INC array and will complain about not finding "Foo::Bar" +there. In this case you can do: eval "require $class";

so BEGIN{ my $var= 'CGI'; eval "require $var"; $var->import(); } should work.

~Particle *accelerates*

Log In?
Username:
Password:

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

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

    No recent polls found