VSarkiss has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a database maintenance app whose operation is controlled from a database table. One type of entry in the table allows calling a sub in the program with a specified argument. (The program checks that the table entry is on a list of safe-to-call subs.)
I can think of two ways to dispatch to the code based on what I've read in. One is to use a symbolic reference:
Another way is to use eval:# Suppose $op is the name of the sub, # and $arg is the argument string to pass to it. if (is_a_safe_sub($op)) { no strict 'refs'; $op->($arg) or warn "Error, blah, blah"; }
if (is_a_safe_sub($op)) { eval "$op($arg)" or warn "Error, blah, blah"; }
I made a hit/miss list that looks like this:
So, brothers and sisters, I humbly seek your counsel. Which way is better, and why? Is there yet a third way I haven't thought about?
TIA
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Style question: symref or eval?
by suaveant (Parson) on Sep 25, 2001 at 20:58 UTC | |
|
(tye)Re: Style question: symref or eval?
by tye (Sage) on Sep 25, 2001 at 21:24 UTC | |
|
Re: Style question: symref or eval?
by dragonchild (Archbishop) on Sep 25, 2001 at 20:58 UTC | |
by suaveant (Parson) on Sep 25, 2001 at 21:02 UTC | |
by dragonchild (Archbishop) on Sep 25, 2001 at 21:04 UTC | |
|
Re: Style question: symref or eval?
by VSarkiss (Monsignor) on Sep 25, 2001 at 22:30 UTC |