Try this:
#!/usr/bin/perl -w use strict; use warnings 'all'; # ...later... load_class("Some::Class"); sub load_class { my ($class) = @_; (my $file = "$class.pm") =~ s/::/\//g; unless( $INC{$file} ) { require $file; $class->import; }# end unless(); }# end load_class()
Just as use <ClassName> operates in compile-time, require operates in runtime without a string eval.
To finish the job, call import on the newly-loaded package and you're done.
In reply to Re: Dynamic Class Loading, Compilation, & Speed
by jdrago999
in thread Dynamic Class Loading, Compilation, & Speed
by zerohero
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |