in reply to Re: Questions concerning /o regex modifier
in thread Questions concerning /o regex modifier

diotalevi,
Ok, but I am still don't understand when and why /o is useful. Would you be kind enough to fill in the blanks?

Cheers - L~R

  • Comment on Re^2: Questions concerning /o regex modifier

Replies are listed 'Best First'.
Re^3: Questions concerning /o regex modifier
by diotalevi (Canon) on Nov 29, 2006 at 21:30 UTC

    Use /o when

    • writing for a perl 5.005 and less.
    • You are nano-optimizing to avoid the null operation of a pp_regcomp given a qr// object

    Use qr// when

    • writing for a perl 5.6 and greater.
    • You want the syntax affordance of being able to say qr/\s/ rather than "\\s" (assuming your interpolating into some larger expression)

    Rely on /$regex/ implementation details when

    • you've bothered to read the source and know exactly what it's doing

    Do not use /o when

    • writing for humans to read (because almost no one understands what /o does)
    • on perls 5.6 and greater
    • ever. It's just bad style now.

    Do not use qr// when

    • on perl 5.005 and lower
    • you're writing a sub expression that's going to be interpolated elsewhere and you care that the regexp compiler takes longer to compile strings like '(?-xism:...)' slower than '...'.

    Do not rely on /$regex/ implementation details when

    • you haven't read the source to pp_regcomp.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      diotalevi,
      Thank you! I will point people to this anytime the discussion comes up.

      Cheers - L~R