http://qs321.pair.com?node_id=838749

bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

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.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot