in reply to calling a function as a value from a hash
I'm with shmem, in that $op_map{$op_choice}->(@args); is the form that feels the most natural. Such a technique is commonly called a "dispatch table".
But it's worth noting that a good to habit to get into is to put a comma at the end of each line, including the last. So you're safer if you put a comma after \&op2, as in:
my %op_map=( 'OP1' => \&op1, 'OP2' => \&op2, );
That's because later, when you add a function or functions at the end, you won't get an error due to a missing comma.
|
|---|