Branch: refs/heads/yves/perlvar_last_successful_match
  Home:   https://github.com/Perl/perl5
  Commit: 8f6446fcaa5d7a9b18054b36e0fd26ec9d5fcfa8
      
https://github.com/Perl/perl5/commit/8f6446fcaa5d7a9b18054b36e0fd26ec9d5fcfa8
  Author: Yves Orton <[email protected]>
  Date:   2023-03-13 (Mon, 13 Mar 2023)

  Changed paths:
    M gv.c
    M mg.c
    M pod/perldelta.pod
    M pod/perlop.pod
    M pod/perlvar.pod
    M t/re/pat.t

  Log Message:
  -----------
  mg.c - add support for ${^LAST_SUCCESSFUL_PATTERN}

This exposes the "last successful pattern" as a variable that can be
printed, or used in patterns, or tested for definedness, etc. Many regex
magical variables relate to PL_curpm, which contains the last successful
match.  We never exposed the *pattern* directly, although it was
implicitly available via the "empty pattern".  With this patch it is
exposed explicitly.  This means that if someone embeds a pattern as a
match operator it can then be accessed after the fact much like a qr//
variable would be.

@ether asked if we had this, and I had to say "no", which was a shame as
obviously the code involved isn't very complicated (the docs from this
patch are far larger than the code involved!).  At the very least
this can be useful for debugging and probably testing. It can also
be useful to test if the /is/ a "last successful pattern", by checking
if the var is defined.


Reply via email to