My rule of thumb is to use white space where possible as you would for prose on the basis that that is what we are most used to parsing so we get a fair bit of the parsing work essentially for free.

I also tend to use whitespace around operators and after commas, but at the same time, personally I can read things like $/=""; easily, which is why I don't always put whitespace around operators if the expression is short - if I'm coding for myself, I just base it on my feeling of readability. If I had to make a choice for a best practice recommendation though, I'd say whitespace around operators is good.

Interestingly regexen are something of an exception for me.

For me, regexes don't always read easily, especially if there's a lot of nested parens going on, so when trying to understand a regex, I'll often add the /x and whitespace.


In reply to Re^5: Question about regex. by haukex
in thread Question about regex. by that_perl_guy

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.