rvosa has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
there are some situations where I need to use/require a class from a variable (say $class). The way I do that is by:
Thanks!
there are some situations where I need to use/require a class from a variable (say $class). The way I do that is by:
...or something to that effect, i.e. by using a string eval. This feels wrong (perlcritic complains about it also). What's the right way?eval "require $class"; if ( $@ ) { die "Can't load $class: $@"; } my $obj = $class->new;
Thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: eval "require $class" seems wrong
by jZed (Prior) on Aug 22, 2007 at 17:37 UTC | |
by rvosa (Curate) on Aug 22, 2007 at 17:43 UTC | |
by rvosa (Curate) on Aug 22, 2007 at 18:03 UTC | |
by tye (Sage) on Aug 22, 2007 at 19:10 UTC | |
by rvosa (Curate) on Aug 22, 2007 at 22:51 UTC | |
by tye (Sage) on Aug 22, 2007 at 23:01 UTC | |
| |
Re: eval "require $class" seems wrong
by ikegami (Patriarch) on Aug 22, 2007 at 17:48 UTC | |
by rvosa (Curate) on Aug 22, 2007 at 17:56 UTC | |
by ikegami (Patriarch) on Aug 22, 2007 at 19:08 UTC | |
by sgt (Deacon) on Aug 22, 2007 at 20:02 UTC | |
by ikegami (Patriarch) on Aug 22, 2007 at 20:12 UTC | |
| |
Re: eval "require $class" seems wrong
by lima1 (Curate) on Aug 22, 2007 at 17:38 UTC | |
by rvosa (Curate) on Aug 22, 2007 at 17:48 UTC | |
by tye (Sage) on Aug 22, 2007 at 19:05 UTC | |
by ikegami (Patriarch) on Aug 22, 2007 at 19:14 UTC | |
by tye (Sage) on Aug 22, 2007 at 19:23 UTC | |
by ikegami (Patriarch) on Aug 22, 2007 at 19:20 UTC | |
by lima1 (Curate) on Aug 22, 2007 at 18:22 UTC |
Back to
Seekers of Perl Wisdom