I am working on a small script using Perl and i am confused which logical operator has to be used for comparing strings
Sample Code :
if (($app eq "appname1")OR($app eq "appname2")OR($app eq "appname3"))
Do i have to use OR (or) ||
I am working on a small script using Perl and i am confused which logical operator has to be used for comparing strings
Sample Code :
if (($app eq "appname1")OR($app eq "appname2")OR($app eq "appname3"))
Do i have to use OR (or) ||
The general rule of thumb tends to be:
|| to combine boolean operations, such as if ($app eq "appname1" || $app eq "appname2" || $app eq "appname3") { ... }or for flow control, such as open my $fh, '<', $filename or die "Open failed: $!"In this case, it doesn't matter, because:
eq has a higher precedence than both || and orHere's what perlop says:
Binary "
or" returns the logical disjunction of the two surrounding expressions. It's equivalent to||except for the very low precedence.
Also note that OR (uppercase) is not a valid Perl operator, but or (lowercase) is.