Hm. That's like advocating always taking a swimsuit & sunblock and a raincoat & umbrella cos it saves listening to the weather forecast.

/m and /s don't add functionality. They modify functionality.

So using /ms is more like rewiring your oddly designed radio so that the tuning dial and the volume control actually work as you expect...thereby—for example—enabling you to successfully listen to weather forecasts.

The very reason it is hard, even for long-time Perlers with scads of frequent regex user miles, to remember which (/s /m) does what, is because they are so rarely required.

I'd argue that they are often required, just rarely used correctly.

In my experience, matching start- and end-of-line is far more commonly needed that matching start- and end-of-string. The default behaviour is wrong practically every time anyone has to deal with multi-line data.

Likewise, the vast majority of .* instances I see in deployed code are being used as "match anything", which they don't.

BTW, it's easy to remember which is which: /s alters the behaviour of a single metacharacter (.) whereas /m alters the behaviour of multiple metacharacters (^ and $).

By using them everywhere they become the norm

Yes, that's precisely the point. The modified behaviours they provide should have been the norm from the start.

after a while people stop asking themselves why is he using that here. And that is bad.

Except that using them everywhere actually makes regexes work the way most people mistakenly think they already work. So even if they don't ask themselves why, they still get the "expected" behaviour.

In other words, using /ms consistently on regexes makes the (idiosyncratic) behaviour of regexes conform to people's (reasonable) expectations, rather than vice versa. It's a simple technique that fixes an infelicity in Perl 5. And that's why PBP recommends it.

Damian


In reply to Re^4: example of 'm / / m' related example and compare to 'm / / s' by Anonymous Monk
in thread PERL regex modifiers for m// by rockstar99

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.