Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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.


Comment on Re: Dynamic Class Loading, Compilation, & Speed
Select or Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-28 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (259 votes), past polls