Perl won't even notice. See also L<"qr/STRING/imosx">.
If the PATTERN evaluates to the empty string, the last
-I<successfully> matched regular expression is used instead.
+I<successfully> matched regular expression is used instead. In this
+case, only the C<g> and C<c> flags on the empty pattern is honoured -
+the other flags are taken from the original pattern. If no match has
+previously succeeded, this will (silently) act instead as a genuine
+empty pattern (which will always match).
If the C</g> option is not used, C<m//> in list context returns a
list consisting of the subexpressions matched by the parentheses in the
{
dSP; dTARG;
register PMOP *pm = cPMOP;
+ PMOP *dynpm = pm;
register char *t;
register char *s;
char *strend;
PL_reg_match_utf8 = DO_UTF8(TARG);
+ /* PMdf_USED is set after a ?? matches once */
if (pm->op_pmdynflags & PMdf_USED) {
failure:
if (gimme == G_ARRAY)
RETPUSHNO;
}
+ /* empty pattern special-cased to use last successful pattern if possible */
if (!rx->prelen && PL_curpm) {
pm = PL_curpm;
rx = PM_GETRE(pm);
}
+
if (rx->minlen > len)
- goto failure;
+ goto failure;
truebase = t = s;
/* XXXX What part of this is needed with true \G-support? */
- if ((global = pm->op_pmflags & PMf_GLOBAL)) {
+ if ((global = dynpm->op_pmflags & PMf_GLOBAL)) {
rx->startp[0] = -1;
if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
MAGIC* mg = mg_find(TARG, PERL_MAGIC_regex_global);
if (CALLREGEXEC(aTHX_ rx, s, strend, truebase, minmatch, TARG, NULL, r_flags))
{
PL_curpm = pm;
- if (pm->op_pmflags & PMf_ONCE)
- pm->op_pmdynflags |= PMdf_USED;
+ if (dynpm->op_pmflags & PMf_ONCE)
+ dynpm->op_pmdynflags |= PMdf_USED;
goto gotcha;
}
else
}
}
if (global) {
- if (pm->op_pmflags & PMf_CONTINUE) {
+ if (dynpm->op_pmflags & PMf_CONTINUE) {
MAGIC* mg = 0;
if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG))
mg = mg_find(TARG, PERL_MAGIC_regex_global);
RX_MATCH_TAINTED_on(rx);
TAINT_IF(RX_MATCH_TAINTED(rx));
PL_curpm = pm;
- if (pm->op_pmflags & PMf_ONCE)
- pm->op_pmdynflags |= PMdf_USED;
+ if (dynpm->op_pmflags & PMf_ONCE)
+ dynpm->op_pmdynflags |= PMdf_USED;
if (RX_MATCH_COPIED(rx))
Safefree(rx->subbeg);
RX_MATCH_COPIED_off(rx);
nope:
ret_no:
- if (global && !(pm->op_pmflags & PMf_CONTINUE)) {
+ if (global && !(dynpm->op_pmflags & PMf_CONTINUE)) {
if (SvTYPE(TARG) >= SVt_PVMG && SvMAGIC(TARG)) {
MAGIC* mg = mg_find(TARG, PERL_MAGIC_regex_global);
if (mg)
$| = 1;
-print "1..897\n";
+print "1..900\n";
BEGIN {
chdir 't' if -d 't';
print eval { "a" =~ /\p{qrst} / } ? "not ok $test\n" : "ok $test\n";
$test++;
}
+
+{
+ # [ID 20020412.005] wrong pmop flags checked when empty pattern
+ # requires reuse of last successful pattern
+ my $test = 898;
+ $test =~ /\d/;
+ for (0 .. 1) {
+ my $match = ?? + 0;
+ if ($match != $_) {
+ print "ok $test\n";
+ } else {
+ printf "not ok %s\t# 'match once' %s on %s iteration\n", $test,
+ $match ? 'succeeded' : 'failed', $_ ? 'second' : 'first';
+ }
+ ++$test;
+ }
+ $test =~ /(\d)/;
+ my $result = join '', $test =~ //g;
+ if ($result eq $test) {
+ print "ok $test\n";
+ } else {
+ printf "not ok %s\t# expected '%s', got '%s'\n", $test, $test, $result;
+ }
+ ++$test;
+}