Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Avoiding if/else knots

by holli (Abbot)
on Aug 18, 2006 at 16:49 UTC ( [id://568218]=note: print w/replies, xml ) Need Help??


in reply to Re: Avoiding if/else knots
in thread Avoiding if/else knots

My approach to that problem would be to write function to map the input to the keys in the hash. Something like
$dispatch{calculate_key{$input}}->(%attr); sub calculate_key { #.. return $key; }


holli, /regexed monk/

Replies are listed 'Best First'.
Re^3: Avoiding if/else knots
by Limbic~Region (Chancellor) on Aug 18, 2006 at 17:00 UTC
    holli,
    Sure except that calculate_key() is going to contain the same if/elsif/else knot that the OP is asking to avoid. The bottom line is that if your conditions are not exact keys then using dispatch tables will not avoid the knot. That isn't to say that it can't help make the code cleaner.

    Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-23 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found