At some point in their life, every programmer decides that, for the problem at hand, the best solution is to create a set of functions and pass their names as variables. It's not.
First, its a security hazard, as users' input should never be used to execute code in your programs. Second, since code doesn't write itself, the functions themselves have to be written and named, so the actual "variable named after function/function named after variable" scheme isn't much different than foo() if (/foo/).
This pseudo-"functional programming" is better written as a hash with the variable name as key and a function ref as value, similar (but not limited) to this example:
Also, with single quotes, 'foo\n' prints foo\n rather than "foo" and a newline.use strict; use warnings; my %hash = ( foo => sub {return "foo\n"}, bar => sub {return "bar\n"}, ); print &{$hash{'foo'}};
Software speaks in tongues of man.
Stop saying 'script'. Stop saying 'line-noise'.
We have nothing to lose but our metaphors.
In reply to Re: Invoke sub whose name is value of scalar
by Erez
in thread Invoke sub whose name is value of scalar
by andreas1234567
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |