in reply to Re: Really Long if/elsif/else blocks
in thread Really Long if/elsif/else blocks

Thanks. But I'm still puzzled. The array, the dispatcher, the state variables. I'm having a really hard time imagining how that would all come together, especially in a way that would be as easy to follow as the original code. Here's a simplified, but still tangled, if/elsif/else block. Could anybody take a gander at what the code would look like with the array, the dispatcher and the state variables?
if($checkPrefix and $base = &driveBase($canon{$tok}, {%$Args, checkPrefix=>0})){ &equivWord($tok, $canon{$tok}, {})} elsif($checkPrefix and $savbase = &is_measure_physics_frac($tok)){ $num_item{$tok} = 1; &baseInscript($tok, {group => $savbase, num_item =>1, root => $tok})} elsif($base =~ /^[a-z,A-Z]$/){ &baseInscript($tok, {group => 'LETTER', root => $tok})}

Replies are listed 'Best First'.
Re^3: Really Long if/elsif/else blocks
by MidLifeXis (Monsignor) on May 30, 2008 at 20:19 UTC

    I'll give it a shot....

    What is nice, is that you can take this to the next level, and break some of your related tests into modules, and write the above in a manner that would allow those modules to register new checks (put $checks setup into registerCheck() and the loop into runChecks).

    registerCheck(test => sub {...}, action => sub {...});

    I have used this method for testing to see if lists of documents and attributes meet certain criteria, saving state for the entire run, and reporting not only on individual items, but the results of the entire run. The logic looks very similar to what I have above.

    --MidLifeXis

      respect. I like this idea.