summaryrefslogtreecommitdiff
path: root/gv.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-03-13 18:46:41 +0100
committerYves Orton <demerphq@gmail.com>2023-03-14 20:09:01 +0800
commitd80a076d049633e9d4622d7f4561cd0cc13177b5 (patch)
treedc564783fd7b92d6c6239115ec64c94a81ce7572 /gv.c
parent6c12e0ee216a4005debef2334035abf818726587 (diff)
downloadperl-d80a076d049633e9d4622d7f4561cd0cc13177b5.tar.gz
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.
Diffstat (limited to 'gv.c')
-rw-r--r--gv.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/gv.c b/gv.c
index 3b3e984da4..0fb23995a6 100644
--- a/gv.c
+++ b/gv.c
@@ -2219,8 +2219,9 @@ S_gv_magicalize(pTHX_ GV *gv, HV *stash, const char *name, STRLEN len,
if (memEQs(name, len, "\007LOBAL_PHASE"))
goto ro_magicalize;
break;
- case '\014': /* ${^LAST_FH} */
- if (memEQs(name, len, "\014AST_FH"))
+ case '\014':
+ if ( memEQs(name, len, "\014AST_FH") || /* ${^LAST_FH} */
+ memEQs(name, len, "\014AST_SUCCESSFUL_PATTERN")) /* ${^LAST_SUCCESSFUL_PATTERN} */
goto ro_magicalize;
break;
case '\015': /* ${^MATCH} */