Set a separate flag for each of $`, $& and $'.
It still works fine in boolean context.
This will allow us to have more refined control over what parts
of a match string to copy (we currently copy the whole string).
require_tie_mod(gv, name, newSVpvs("Tie::Hash::NamedCapture"), "TIEHASH", 0);
}
if (sv_type==SVt_PV || sv_type==SVt_PVGV) {
- if (*name == '[')
- require_tie_mod(gv,name,newSVpvs("arybase"),"FETCH",0);
- else if (*name == '&' || *name == '`' || *name == '\'') {
- PL_sawampersand = TRUE;
- (void)GvSVn(gv);
- }
+ switch (*name) {
+ case '[':
+ require_tie_mod(gv,name,newSVpvs("arybase"),"FETCH",0);
+ break;
+ case '`':
+ PL_sawampersand |= SAWAMPERSAND_LEFT;
+ (void)GvSVn(gv);
+ break;
+ case '&':
+ PL_sawampersand |= SAWAMPERSAND_MIDDLE;
+ (void)GvSVn(gv);
+ break;
+ case '\'':
+ PL_sawampersand |= SAWAMPERSAND_RIGHT;
+ (void)GvSVn(gv);
+ break;
+ }
}
}
else if (len == 3 && sv_type == SVt_PVAV
sv_type == SVt_PVCV ||
sv_type == SVt_PVFM ||
sv_type == SVt_PVIO
- )) { PL_sawampersand = TRUE; }
+ )) { PL_sawampersand |=
+ (*name == '`')
+ ? SAWAMPERSAND_LEFT
+ : (*name == '&')
+ ? SAWAMPERSAND_MIDDLE
+ : SAWAMPERSAND_RIGHT;
+ }
goto magicalize;
case ':': /* $: */
*/
PERLVAR(I, dowarn, U8)
-PERLVAR(I, sawampersand, bool) /* must save all match strings */
+PERLVAR(I, sawampersand, U8) /* must save all match strings */
PERLVAR(I, unsafe, bool)
PERLVAR(I, exit_flags, U8) /* was exit() unexpected, etc. */
PL_minus_F = FALSE;
PL_doswitches = FALSE;
PL_dowarn = G_WARN_OFF;
- PL_sawampersand = FALSE; /* must save all match strings */
+ PL_sawampersand = 0; /* must save all match strings */
PL_unsafe = FALSE;
Safefree(PL_inplace);
S_run_body(pTHX_ I32 oldscope)
{
dVAR;
- DEBUG_r(PerlIO_printf(Perl_debug_log, "%s $` $& $' support.\n",
- PL_sawampersand ? "Enabling" : "Omitting"));
+ DEBUG_r(PerlIO_printf(Perl_debug_log, "%s $` $& $' support (0x%x).\n",
+ PL_sawampersand ? "Enabling" : "Omitting",
+ (unsigned int)(PL_sawampersand)));
if (!PL_restartop) {
#ifdef PERL_MAD
#define HINT_SORT_MERGESORT 0x00000002
#define HINT_SORT_STABLE 0x00000100 /* sort styles (currently one) */
+/* flags for PL_sawampersand */
+
+#define SAWAMPERSAND_LEFT 1 /* saw $` */
+#define SAWAMPERSAND_MIDDLE 2 /* saw $& */
+#define SAWAMPERSAND_RIGHT 4 /* saw $' */
+
/* Various states of the input record separator SV (rs) */
#define RsSNARF(sv) (! SvOK(sv))
#define RsSIMPLE(sv) (SvOK(sv) && (! SvPOK(sv) || SvCUR(sv)))