in reply to Efficiency & Maintenance: if/elsif or Other Dispatch Method
In other situations, it is resource prohibitive to store every possible condition ($outcome in your example) in the hash though the number of end states ($rv in your example) is quite manageable. In these situations I like to combine a smart search routine with a dispatch table:my $rv = $lookup{$outcome};
In this particular case I have implied a binary search but it could be sequential as you have shown if that scenario fits your data. The point is you abstract finding the item in a list as well as what action to take upon the result.$dispatch->{bin_search($outcome)}->();
Cheers - L~R
|
|---|