Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Would you use 'goto' here?

by Fletch (Chancellor)
on Dec 06, 2001 at 07:03 UTC ( #129841=note: print w/ replies, xml ) Need Help??


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 . . .).


Comment on Re: Would you use 'goto' here?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://129841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2015-07-06 04:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls