in reply to Re: Best Practice: Order of regex modifiers?
in thread Best Practice: Order of regex modifiers?

Hi Hauke,

Thanks, I ignored the "natural order" of perldocs ;-)

> Update: Also, I often place those modifiers that change the behavior of the regex, like /gc, first, so they're immediately obvious.

Well all modifiers change the behaviour of a regex, don't you think?

(I think that's why they are called modifiers ;-)

This leads to my suggestion to order (or at least group) by importance...

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!

  • Comment on Re^2: Best Practice: Order of regex modifiers?

Replies are listed 'Best First'.
Re^3: Best Practice: Order of regex modifiers?
by haukex (Archbishop) on Feb 01, 2017 at 15:46 UTC

    Hi Rolf,

    Well all modifiers change the behaviour of a regex, don't you think?

    Well yes, but: some change how the pattern of the regex is treated, like /xmsialud, whereas some change how the regex operator, like m//, behaves. For example, the return values of m// are quite different from those of m//g, and /g doesn't affect how the pattern is treated.

    Regards,
    -- Hauke D

      Hi Hauke,

      I agree that modifiers like /gcr are fundamentally changing the command.

      That's why in other languages like JS one really needs different commands to achieve the same results.

      There is no easy answer how to prioritize the order...

      ...if possible commands called sr/// or mg// would IMHO be the best choice.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!