in an ultra-lightweight webserver I have this code:
sub loadCode { my $this = shift; my $scrref = &getFileAsString($this->{filename}); # load into the re +gistry $this->{code} = sub {eval($$scrref);}; # store the script in a +n anonymous subroutine }
The code is then executed as &{$this->{code}};. This works - to a certain extent - well. As already stated in the camel book, the eval EXPR is much slower than the eval BLOCK syntax. And if I do cut&paste code and do a BLOCK after eval (resulting in sub {eval { <verbatim perl-code here...> }; }, execution gets about 18times faster.
My problem is simple: I'm greedy ;-) - that is - I would like to benefit from the speedup, but also be able to initialize these anonymous subroutines at startup of the script (they do not need to be changed at runtime).
I thought about constructing perl source code by another script, but before I'd do such a kludgy solution, I wanted to ask you if there is not a better solution. All in all: mod_perl must do something similar - no?
Thank you for your suggestions.
Bye
PetaMem All Perl: MT, NLP, NLU
In reply to eval BLOCK with runtime-loaded code? by PetaMem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |