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!
Back to
Seekers of Perl Wisdom