title: How do you create a callback function (dispatch table) in Perl using hashes?
body: <p>I want to call a main controller function that dispatches other function dynamically, something like this:</p>
  
  <pre><code>package Controller;
  
  my %callback_funcs = ();
  
  sub register_callback{
     my ($class,$callback,$options) = _@;
     #apppend to %callback_funcs hash ... ?
  }
  
  sub main{
  %callback_funcs = ( add =&gt; 'add_func', rem =&gt; 'remove_func', edit =&gt; 'edit_func');  
    while(&lt;STDIN&gt;){
       last if ($_ =~ /^\s*$/);
       if($_ == 'add' || _$ == 'rem' || _$ == 'edit'){
          $result = ${callback_funcs['add']['func']}(callback_funcs['add']['options']);
       }
    }
  }
  
  sub add_func{
  ...
  }
  </code></pre>
  
  <p>One caveat is that the subs are defined in other Modules, so the callbacks would have to be able to reference them... plus
  I'm having a hard time getting the hashes right!</p>