Home: General Discussions: General Questions:
&& in perl



rkr
New User

Feb 14, 2018, 12:10 AM


Views: 5678
&& in perl

I am new to perl.. could you please explain the relevance of && in this if statement.. what does that mean ?

elsif($rf1{$joint} > 1.0 && $rf > 1.05 && $rf < 1.5)

thanks


(This post was edited by rkr on Feb 14, 2018, 1:29 AM)


BillKSmith
Veteran

Feb 14, 2018, 7:44 AM


Views: 5669
Re: [rkr] && in perl

The short answer to your question is that your elsif is true only if all three of the 'greater than' expressions are true.

The '&&' is a 'logical and' operator. It returns a true value if both of its arguments are true (otherwise it returns a false value) In Perl, there are three values which are 'false' (undef, null string, and number 0). All other values are 'true'. In order to understand your statement, it necessary to also know that the '&&' operator has a lower precedence than the '>' operator. This means that the '>'s are evaluated before the '&&'s. The arguments for the first && are the results to the first two comparisons. The arguments of the second '&&' are the result of the first '&&' and the result of the third '>'.

You can use the perl documentation reader 'perldoc' to get the official explanation.
Learn to use the tool:

Code
perldoc perldoc

Read about the operators:

Code
perldoc perlop

Good Luck,
Bill