... more consistent ...

I haven't gone back to review in detail the rationale presented in Perl Best Practices (PBP), but off the top of my head...

Of course, the reason for   Update: the PBP recommendation of   the unvarying use of the  /xms regex modifier 'tail' (if that's the proper term) is to give the  ^ $ . regex operators unvarying behaviors, and the programmer a few fewer things to worry about; because they're always there, their proper place is in the tail.

One thing that cannot be made invariant from regex to regex is case insensitivity. Where, then, to put the  /i modifier? If in the modifier tail, it's in danger of being 'lost', and moreover has global effect upon the regex. If in the body of the regex, it's in your face, and has the added advantage of being more flexible: the effects of the  (?i) and  (?-i) extended pattern modifiers are dependent upon the 'scoping' of the regex capturing and non-capturing groups in which they may appear   (Update: see docs linked below for details).

I.e., the mixture of  qr{pat}xms with  qr{pat}xmsi (or m// or s///) regex definitions is actually less consistent! Moreover, the  (?i) extended pattern allows one to precisely define and control the desired matching behavior.

Of course, the PBP recommendations are not without controversy. I will only repeat the words of a great Marxist philosopher (Groucho): "These are my principles. If you don't like them, I've got others."

See Extended Patterns in perlre for detailed info on the behavior of  "(?pimsx-imsx)" and  "(?imsx-imsx:pattern)" patterns, especially on the 'scope' of their effect.

Updates:

  1. Added link to docs.
  2. Qualified 2nd paragraph text per JohnGG.


In reply to Re^3: Capturing string matched by regex by AnomalousMonk
in thread Capturing string matched by regex by tunafish

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.