Hi there, I'm reading the variable $selectcriterium, either being '<' or '==' and then want to use them for a selection between two other variables also read in. Surely it must be possible to write the following code more effectively and shorter. I just failed to find the way. Can you advise me, please. Thanks, Gerd
#!/usr/bin/perl #These are the variables to be read in my $number1 = '2011'; my $number2 = '2011'; my $selectioncriterium = '=='; #This is the algorithm if ($selectioncriterium eq '<') { if ($number1 < $number2) { print "$number1 is smaller than $number2\n"; } elsif ($number2 < $number1) { print "$number2 is smaller than $number1\n"; } } elsif ($selectioncriterium eq '==') { if ($number1 == $number2) { print "$number1 is equal to $number2\n"; } else { print "$number1 is not equal to $number2\n"; } }
In reply to Passing logical operators on as content of scalar by gm40
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |