in reply to Re^3: eval "require $class" seems wrong (::)
in thread eval "require $class" seems wrong
Okay, well, so in the general case (including '::' in module names), the non-string-eval way to do it seems to be:
# turn $class name into $path my $class = 'Some::Class'; my $path = $class; $path =~ s/::/\//g; $path .= '.pm'; # check if $path already loaded if ( not exists $INC{$path} ) { # do block eval on $path eval { require $path }; die "Can't load $class: $@" if $@; } # if we make it here, we can use $class my $obj = $class->new;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: eval "require $class" seems wrong (code)
by tye (Sage) on Aug 22, 2007 at 23:01 UTC | |
by rvosa (Curate) on Aug 23, 2007 at 14:10 UTC | |
by tye (Sage) on Aug 23, 2007 at 14:45 UTC |
In Section
Seekers of Perl Wisdom