http://www.perlmonks.org?node_id=129841


in reply to Would you use 'goto' here?

You could always use a hash of coderefs to make a jump table.

my %query_to_sub = ( officeID => \&edit_office_product, fnord => \&vreemflitzel ); $query_to_sub{ $query->param( 'spoo' ) }->()

Or if you've got a module, just call the apropriate method on it (if it can()).

my $method = $foo->can( $query->param( 'behavior' ) ); if( defined( $method ) ) { $foo->$method() } else { do_error( "Unknown method " . $query->param( 'behavior' ) ); }

Of course if you're going to get OOPy this would be something you could use a State/Strategy to represent the behavior (which reminds me I really should write a review of Design Patterns and Refactoring like I've been meaning to for a while now . . .).