Fellow Monasterians,
I've searched the "Internets" and the library here in the monastery, but can't find anything definitive. Read lots of stuff about dispatch tables and anonymous subs, and tried several approaches but epic fails. Here's what I'm trying to do. Thoughts? TIA.
my $sub = 'do_this'; print $sub("Fred"); sub do_this { my $var = shift; return "My name is $var"; } sub do_that { my $var = shift; return "My name is not $var"; } My name is Fred
UPDATE: I start getting nervous making exceptions to strict to make things work below, but more importantly, to kennethk's point (below) I might want to rethink why I'm using a variable for a variable name. I had tried to do this many years ago for simple scalars, but got a lesson from one of the senior monks at the time about using hashes, and it changed everything. So, a simple conditional statement or dispatch table might be a better practice.
In reply to Is it possible to use a scalar to call a subroutine? by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |