
Kenosis
User
Mar 2, 2013, 12:36 PM
Post #3 of 8
(1422 views)
|
Re: [ashish_chand] condtion check
[In reply to]
|
Can't Post
|
|
What a great question! There's some Perl short circuiting demonstrated here. For example: is functionally equivalent to: Why? Perl evaluates the first conjunct $f == 1 and, if true, proceeds to evaluate the second so the overall && statement can be evaluated. However, if the first conjunct is false, there's no need to evaluate the second, since the overall && statement is (already) false. This is the short circuit effect and why it's equivalent to $f = 0 if $f == 1. Obviously, this can impact code readability, as does using variables named only $f and $q. We can see exactly how Perl views this short circuiting:
perl -MO=Deparse,-P -e '$f == 1 and $f = 0' $f = 0 if $f == 1; -e syntax OK Notice that it parsed the and statement (used here instead of &&) as a conditional statement. Curiously, the code's author implicitly used Perl's default scalar, viz., $_, in the matching statement /"/, yet chose to use substr to remove its first character, instead of a substitution like s/.//.
(This post was edited by Kenosis on Mar 2, 2013, 12:38 PM)
|