in reply to Re: Help with a logical structure for an if statement
in thread Help with a logical structure for an if statement
It's often better to use 'and' and 'or' (lower precedence than '&&' and '||')I don't get this. Lower precedence operators are better to use than higher precedence ones, even if they have existed in Perl longer, and are used in a myriad of other languages? If so, do you have some arguments to back up this claim?
Perhaps you meant to write "I would use" where you wrote "It's often better to use"?
I would write it as:
That is, I'd lose the redundant parenthesis, use the standard operators, and use whitespace to make the symmetry clear. Or:if ($player_one_race eq 'terran' && $player_two_race eq 'zerg' || $player_one_race eq 'zerg' && $player_two_race eq 'terran') { ... }
my %races; $races{$_} = 1 for $player_one_race, $player_two_race; if ($races{zerg} && $races{terran}) { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Help with a logical structure for an if statement
by tobyink (Canon) on Apr 30, 2012 at 07:43 UTC | |
|
Re^3: Help with a logical structure for an if statement
by brx (Pilgrim) on Apr 30, 2012 at 09:12 UTC |