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.


In reply to Re: Operator precedence by knobunc
in thread Operator precedence by Kickstart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.