summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-04-24 13:31:45 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-05-21 16:51:35 -0700
commitd9bad346a16eb87a6306ab3d32ca301cc10d1323 (patch)
treeb3357ec9526de73ae6fbf068dd083ee65d60c1ee /mg.c
parent8fdd8881452abe4af47ade816591f235440f7885 (diff)
downloadperl-d9bad346a16eb87a6306ab3d32ca301cc10d1323.tar.gz
[perl #112184] Handle $^N in Perl_magic_set
$^N is a magical variable, like $1 and $2, with the usual ‘sv’ magic. So it is handled by Perl_magic_get and Perl_magic_set. But Perl_magic_set didn’t have a case for it, so it simply ignored it and did nothing, like a tied variable with an empty STORE method. Now assigning to $^N has the same affect as assigned to the numbered variable to which it corresponds. If there is no corresponding cap- ture from the last match, or in the absence of regexp plugins, it croaks with ‘Modification of a read-only value’.
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/mg.c b/mg.c
index 03500da7ca..9acd5d22ec 100644
--- a/mg.c
+++ b/mg.c
@@ -2519,11 +2519,13 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
paren = atoi(mg->mg_ptr);
setparen:
if (PL_curpm && (rx = PM_GETRE(PL_curpm))) {
+ setparen_got_rx:
CALLREG_NUMBUF_STORE((REGEXP * const)rx,paren,sv);
} else {
/* Croak with a READONLY error when a numbered match var is
* set without a previous pattern match. Unless it's C<local $1>
*/
+ croakparen:
if (!PL_localizing) {
Perl_croak_no_modify(aTHX);
}
@@ -2598,6 +2600,10 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg)
Safefree(PL_inplace);
PL_inplace = SvOK(sv) ? savesvpv(sv) : NULL;
break;
+ case '\016': /* ^N */
+ if (PL_curpm && (rx = PM_GETRE(PL_curpm))
+ && (paren = RX_LASTCLOSEPAREN(rx))) goto setparen_got_rx;
+ goto croakparen;
case '\017': /* ^O */
if (*(mg->mg_ptr+1) == '\0') {
Safefree(PL_osname);