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