[...]
Rainer> I really don't know why you think that running the Perl compiler from
Rainer> within Perl-code in order to create new compiled code should be
Rainer> avoided. I'll happily learn the reason for that, though.
Keep reading. I'm not going to repeat things that have been said
repeatedly in the literature for at least a dozen years.
Out of curiosity, I've now also done a very cursory 'literature
search': The Camel-book, considering its usual 'no bullshit' approach
to technology', contains nothing applicable to this particular way of
using eval. Something which is easily available on the web,
http://docstore.mik.ua/orelly/perl/advprog
has a quite enthusiastic chapter on eval,
http://docstore.mik.ua/orelly/perl/advprog/ch05_01.htm
containing the following statement:
For me, Perl's run-time evaluation capability is one of the
biggest reasons for using the language. I use run-time
evaluation for creating little snippets of code on the fly,
which then execute at typical Perl speeds (i.e., fast!), for
writing sophisticated interpreters for little languages. The
eval function is the gateway to this power.
Lastly, I also found this:
No. Do not resort to eval-string if other means are
available. You're firing up the compiler (slower than almost
any other solution), and exposing yourself to hard to debug
and hard to secure practices.
http://www.perlmonks.org/?node_id=405165
While this statement is arguably true (Imagine that it even provides a
reason and not just a commandment!) it is also not really applicable
when using the compiler to compile some frequently executed piece of
code in order to reduce the time needed to execute it: Doing a very
unscientific experiment (meaning, "just ran it once"), the eval is
indeed about an order of magnitude slower than the closure-creation
but this will amortize itself (insofar total CPU time used is
concerned) if the completely compiled function is called more than
about 213 times. Also, there are of course situations where one
instance of 'doing something' with a relatively high latency in order
to have a lower latency when 'doing something' in future is a sensible
tradeoff.
I feel like closing this posting with a German paragraph because I'd
like to use an absolutely untranslatable 'Daniel Duesentrieb' quote
in it (that's Gyro Gearloose in English)
"In des tumben Toren Hand ist jedes Werkzeug Tand" ist sicher
zutreffend. Allerdings nicht der Umkehrschluss das jeder, der ein
Werkzeug in die Hand nimmt, wohl ein tumber Tor sein muesse ...