I am assuming that you are looking for ways people remember precedence and I am not sure that there are any. For the most part they follow mathematic syntax or C. If there is extra stuff then for the most part it was where Larry Wall et al. thought made sense.
Well you could do a perldoc perlop and read the precedence rules which state that =~ has a higher precedence than lc (a named unary operator). After much memorizing you could be an all poweful pecedence ninja and never need extra parentheses.
However, if you want other people to be able to read it easily then I would recommend putting in parentheses where it makes sense to do so. Also using the 'english' 'and', 'not', and 'or' operators instead of &&, !, or || since they have very low precedence and tend not to need parentheses around the clauses nearest them. (Not that you had any of those guys so may already follow that rule)
So, because I like functional notation, I would write:
if ( lc($foo) =~ lc($bar) ) {
...
}
Although to be absolutely honest I would have written:
if ( index( lc($foo), lc($bar) ) != -1 ) {
print "Yes\n";
} else {
print "No\n";
}
Because it is probably faster than using the regexp enging.
-ben
Bah, sorry for the duplicate post, there were no responses when I started. |