But that's the point: you never use anything other than an /xms tail in your own code.
I dunno, that seems unnecessarily rigid. A "best practice" should mean "do this unless there's a good reason to do otherwise," not "always blindly do this no matter what." All three of those options modify the regex behavior. What if you need the unmodified behavior?
I realize "need" might be too strong a word; with /x, for instance, you can always just escape any literal space characters your regex needs. But if there are several of them, and your regex is otherwise simple, all those escapes clutter the code more than just omitting the /x. And someone else encountering m/a\ b\ c/xms in your code will wonder what tricky thing you're trying to do by telling the regex engine to ignore whitespace and then escaping all your whitespace.
I'm not saying your system is wrong — I'm certain it serves you well — but I don't think I'm sold on it yet.
| [reply] [d/l] [select] |
What if you need the unmodified behavior?
But what unmodified behavior would you need that you would not be able to access in a fairly clear and simple manner? E.g., if you're using /s and you want the "match anything except a newline" behavior, does not [^\n] best express this? (One of the driving motivations of TheDamian's regex PBPs is clarity of expression.)
Conversely, in the absence of /s, how would you best express "match anything at all, including a newline" (the most common use-case, IMO)? Something like [\s\S] would do the trick, but is that anyone's idea of clarity? (And don't get me started on (?s:.) ...)
... with /x ... you can always just escape any literal space characters your regex needs. But ... all those escapes clutter the code ...
I must admit that the need for special handling of spaces can be annoying. But even this can advance clarity: [ ] (I would not use \) matches a blank space exactly; [ \t] matches a blank space or a tab exactly; \s matches any whitespace exactly; etc... (You may object that \s is too general, but there've been several occasions on which I've been saved from a 3 AM phone call by having used \s rather than a more specific [ ] — or even \) And \Q...\E can help out, too.
Anyway, TheDamian explains it all more completely and clearly than I can, so maybe pursue that avenue.
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |
if you're using /s and you want the "match anything except a newline" behavior, does not [^\n] best express this?
In the context of /s, sure. But again, there is a larger context: someone else reading the regex will wonder at the incongruity of using /s at all in conjunction with a bunch of [^\n]s, when omitting the /s would simplify the whole thing (and also make the regex syntax match that used by most other regex engines, a consideration — albeit minor — when aiming for clarity).
One of the driving motivations of TheDamian's regex PBPs is clarity of expression.
A goal we can all agree with! Now, enter devils and details.
Anyway, TheDamian explains it all more completely and clearly than I can, so maybe pursue that avenue.
Point taken. I'm sure my perl experience is a tiny fraction of either yours or his.
| [reply] [d/l] [select] |