|more useful options|
Avoiding if/else knotsby loris (Hermit)
|on Aug 18, 2006 at 12:22 UTC||Need Help??|
loris has asked for the
wisdom of the Perl Monks concerning the following question:
Faced with the prospect of mapping a dozen or so cases defined by half a dozen attributes on to two or three actions which just set flags or scalars, I thought that, rather than tacking more ifs and elses onto the existing code, it might be a good idea to use a hash. I would have to convert relevant combinations of attributes into a form that I could use as a hash key and the corresponding values for the resulting actions into a hash value.
Has anyone used this approach before and knows of any caveats? Or does anyone have a better idea? I should say that I shall actually be implementing this in Java, so I won't be able to make use of any particularly Perly solutions, although I would still be insterested in them.
"It took Loris ten minutes to eat a satsuma . . . twenty minutes to get from one end of his branch to the other . . . and an hour to scratch his bottom. But Slow Loris didn't care. He had a secret . . ."