Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Dynamic Class Loading, Compilation, & Speed

by cdarke (Prior)
on Mar 06, 2010 at 23:04 UTC ( #827174=note: print w/replies, xml ) Need Help??

in reply to Dynamic Class Loading, Compilation, & Speed

Rather than using eval with a string, it is probably better to use a block. For example:
y $class = 'gash'; eval { require "$class.plm" }; die "Oops: $@" if $@; my $obj = $class->new();
It will not recompile the class each time, perl maintains %INC to record modules loaded.

Replies are listed 'Best First'.
Re^2: Dynamic Class Loading, Compilation, & Speed
by zwon (Monsignor) on Mar 06, 2010 at 23:14 UTC
    require "$class.plm"

    Note, that won't work if $class='My::Class', you have to replace '::' with '/'. Module::Load takes care about this.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2016-10-22 02:22 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.