in reply to Re: Avoiding if/else knots II
in thread Avoiding if/else knots II
I'm asking myself what's the advantage of first mapping values to keys and then dispatching the keys via a hash table instead of skipping the key and dispatching directly.
So in all the cases where you have a $key= somethin you could also write down a call of a subroutine handling this key. Except for the default case of course.
I'd write your example like this:
SWITCH: for ( $myValue ) { /$reg2/ && do { sub_for_key_a(); last SWITCH; }; /$reg1/ && do { whatever(); sub_for_key_b(); last SWITCH; }; #default sub_for_default(); } # END SWITCH
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Avoiding if/else knots II
by shmem (Chancellor) on Aug 30, 2006 at 09:43 UTC | |
by Skeeve (Parson) on Aug 30, 2006 at 10:09 UTC | |
by shmem (Chancellor) on Aug 30, 2006 at 12:44 UTC | |
by Skeeve (Parson) on Aug 30, 2006 at 20:17 UTC |