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

Thanks for the clarification. °

Honestly, when injecting code evaluation into a variable interpolation, I'm not surprised to get inconsistent side effects.

It would be of bigger concern if it also happened with more "official" means like (?{...}) or (??{...})

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

°) how popular are Perl builds without thread support?

Replies are listed 'Best First'.
Re^19: Reusing a complex regexp in multiple spots, escaping the regexp
by dave_the_m (Monsignor) on Apr 17, 2026 at 15:29 UTC
    The "code injection" was just a quick and dirty demonstration of a side-effect. Its shows that on a threaded build, the expression which defines the pattern is assembled each time, but then thrown away unused apart from the first iteration. Think for example of a tied array. The following:
    for my $i (0,1) { /abc$tied_array[$i]/; }
    will, on threaded builds, invoke both $tied_array->FETCH(0) and $tied_array->FETCH(1), but will discard the second value.

    Dave.

      Thanks for the better example!

      Does this double execution also effect officially embedded (?{CODE}) ?

      Shouldn't this be just documented with /o or (in a better world) even better emitting a warning?

      I'm using side effects in regexes mainly for debugging.

      On a tangent: My system Perl seems to be with thread support, I dunno how often Perl is even installed or used without thread support.

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