in reply to I need help with a bunch of "if/elsif statements (comparisons)"

Those <p> tags in your code and/or your formatting leave your script quite unreadable.

I also can't decipher from your description what exactly you want to do. What are the input values $best_X, $best_Y, $block1, $block2, $position2, position1 ... and how are they related to each other? What do the numbers 110, 100 and 70 have to do with your problem?

  • Comment on Re: I need help with a bunch of "if/elsif statements (comparisons)"

Replies are listed 'Best First'.
Re^2: I need help with a bunch of "if/elsif statements (comparisons)"
by erons (Initiate) on Jan 27, 2010 at 16:51 UTC

    Hi, the numbers: 110, 70, 100, etc relate to the different cut-off at which I want to call bestmatch+TE or bestmatch-TE or unique match. I need to do this for two diffrent IDs(have the best scores) and then compare the agreement between them. For example, if best_X gives bestmatch+TE, does best_Y also give the same result? my aim was to keep the call in $resH

      Ok, I'm still not sure what exactly should happen but it seems you first want to classify both ids in the same way. This is a job for a subroutine, so that you don't have to do that twice:

      sub award_score { #awards one of three scores to a tupel of # best result,block and position. The scores are # ... my ($best,$block,$position)= @_; my $result="nothing"; if ($best<100 and $block<100) { ... $result='best_match-TE' } elsif { ... $result= ... } return $result; }

      Now that you have a well defined and (hopefully) well documented subroutine to do the preliminary work on each individual score, you can add the main code:

      my $result_x= award_score($best_x,$block1,$position1); my $result_y= award_score($best_y,$block2,$position2); if ($result_x eq $result_y) { ... }

      This is only a rough draft that you have to adapt, it is just to show you the principle. Somehow or other a similar method should work for you. If you need more parameters into the subroutine, just do that. If you need to return more than one result, likewise no problem. If your main routine looks so simple that someone else could understand it immediately you have won

      PS: variable names like $nTE2 are cryptic and not very helpful if you or someone else has to understand the code one year later