in reply to Small examples of string eval
Most Perl experts discourage the use of string eval. For example:
- merlyn in •Re^2: Dynamically constructed function calls states: 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.
- TheDamian in Perl Best Practices in Chapter 8 has a guideline titled: Avoid string eval. Damian argues that string eval can be slow; produces run time warnings rather than more desirable compile time warnings; and code that generates other code tends to be harder to maintain. He further advises you to use anonymous subroutines and the CPAN Sub::Installer module when you have a need to create new subroutines that are built around some expression that the user supplies.
Update: In this quiz of the week MJD states:
A good rule of thumb is that unless what you're trying to do is most clearly described as "compile and run arbitrary Perl code", it's probably a mistake to use 'eval' to do it.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Small examples of string eval
by BrowserUk (Patriarch) on May 13, 2006 at 18:12 UTC | |
by spurperl (Priest) on May 14, 2006 at 03:59 UTC | |
Re^2: Small examples of string eval
by stvn (Monsignor) on May 13, 2006 at 15:12 UTC |
In Section
Seekers of Perl Wisdom