in reply to Best Practice: Order of regex modifiers?
G'day Rolf,
Purely for readability, I generally try to keep the modifiers in alphabetical order. In that respect, I concur with ++hippo's response.
I'm pretty sure that the "xms default" came about, because that was the order they were introduced in the book "Perl Best Practices".
Some modifiers can be applied to the regex itself (e.g. /x); others, to any operation the regex is involved in (e.g. /g); and others to only a specific operation (e.g. /e). It's a fatal error to use them in the wrong places:
$ perl -E 'say qr{}x' (?^ux:) $ perl -E 'say qr{}g' Unknown regexp modifier "/g" at -e line 1, near "say " Execution of -e aborted due to compilation errors. $ perl -E 'say m{}g' $ perl -E 'say m{}e' Unknown regexp modifier "/e" at -e line 1, near "say " Execution of -e aborted due to compilation errors. $ perl -E 'say s{}{}e' 1
I can see some benefit in keeping those grouped together: your initial example of xegis would become isxge.
I'm also not averse to ++AnomalousMonk's suggestion of using a separator. In which case, xegis would become isx_g_e.
Overall, I'm not too bothered by personal preferences regarding modifier ordering: deciding upon a single style, and using it consistently, is far more important, in my opinion.
— Ken
|
|---|