A.10 Operator Precedence


Operator precedence determines the order in which the operations are applied. For instance, in Perl, the expression:

 3 + 3 * 4 

isn't evaluated left to right, which calculates 3 + 3 equals 6, and 6 times 4 results in a value of 24; the precedence rules cause the multiplication to be applied first, for a final result of 15. The precedence rules are available in the perlop manpage and in most Perl books. However, I recommend you use parentheses to make your code more readable and to avoid bugs . They make the following expressions unambiguous; the first:

 (3 + 3) * 4 

evaluates to 24, and the second:

 3 + (3 * 4) 

evaluates to 15.



Mastering Perl for Bioinformatics
Mastering Perl for Bioinformatics
ISBN: 0596003072
EAN: 2147483647
Year: 2003
Pages: 156

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net