in reply to Re^13: Reusing a complex regexp in multiple spots, escaping the regexp
in thread Reusing a complex regexp in multiple spots, escaping the regexp

> The longest explanation of /o

This covers exactly my understanding.

You'll also find this in perlop for m//

- "But now, the only reasons to use /o are one of:..."

The perldocs are vast and often redundant, and sometimes contradictory.

They are like much of the code base a collaborative design.

The wording at perlre is at best dubious and as far as I can see not substationated.

As long as nobody shows me a real bug caused by /o I'd call this BS.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

  • Comment on Re^14: Reusing a complex regexp in multiple spots, escaping the regexp

Replies are listed 'Best First'.
Re^15: Reusing a complex regexp in multiple spots, escaping the regexp
by dave_the_m (Monsignor) on Apr 17, 2026 at 11:52 UTC
    Well for example, consider the following code:
    for my $i (1..2) { print "match\n" if "x1" =~ /x${print "doing arg\n"; \1}/o; }
    On threaded perls it prints "doing arg" twice; on unthreaded, once.

    Dave.

      > on unthreaded, once.

      I tried your code on "unthreaded" perl and it prints twice.

      It seems like this weird "interpolation" ° resolves to "x1" =~ /x1/ which doesn't make much sense as a bug demo.

      I don't understand how this is proving anything???

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

      °) seems like you are dereferencing a ref to the literal number 1

      DB<1> say "${\1}" 1

      you probably meant a the regex back-reference to the first match \1 ? But there is no first match ... ehm???

        I tried your code on "unthreaded" perl and it prints twice. It seems like this weird "interpolation" ° resolves to "x1" =~ /x1/ which doesn't make much sense as a bug demo.

        On a perl interpreter compiled without threads support it prints "doing arg" once; on a threaded perl interpreter it prints twice - see the example run below. The match itself works correctly in both cases: it resolves to /x1/. My example was to show that there are strange side-effects which depend on the particlar perl interpreter you run it under. There are other edge case effects, the details of which I can't recall off the top of my head.

        $ perl5420 -v This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-li +nux $ perl5420 ~/tmp/p doing arg match match $ perl5420t -v This is perl 5, version 42, subversion 0 (v5.42.0) built for x86_64-li +nux-thread-multi $ perl5420t ~/tmp/p doing arg match doing arg match $

        Dave.

      Thanks!

      Please, how can I reproduce this?

      There are multiple threaded Perl models.

      I never wrote threaded Perl¹, so please explain

      • What's the output without /o then?

      And as follow ups

      • How does this qualify as a bug and not a feature?
      • Is state better in this respect? °
      • Shouldn't this be documented as side effect, (at least with a footnote)?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery

      Footnotes

      °) updated

      ¹) I suppose only a tiny minority ever did.

        I think "threaded perl" means an interpreter compiled with -Dusethreads. It changes the output regardless of whether you use threads in the code or not.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]