Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re^4: Finding out which of a list of patterns matchedby tirwhan (Abbot) |
on Jan 22, 2006 at 16:14 UTC ( [id://524797]=note: print w/replies, xml ) | Need Help?? |
By "my method" I meant using capturing parentheses and $1 to retrieve the match, instead of $#-. The dispatch table is just the next step and not tied to the method of finding the value to act on. But regardless of that, what's the problem with a long dispatch table? You don't actually need to store the actions as anonymous subs of course, if you have several values which correspond to the same action you just use references to subs which you define elsewhere. This is certainly more manageable than endless if-elsif blocks. Sure, it's no silver bullet (e.g. if you only have three actions which each map to 1000 possible keywords you probably wouldn't go that way), but without knowing more about the OPs requirements it's impossible to tell how appropriate the solution is. Maybe I'm not understanding your objection correctly though, would you care to give a solution that's more manageable for 5000 values? Update: here's an example of how you could set up a dispatch table with lots of values matching to less (and potentially longer) subroutines:
Seems manageable to me, even if you imagine this expands by a considerable amount. There are ten types of people: those that understand binary and those that don't.
In Section
Seekers of Perl Wisdom
|
|