From: Ilya Zakharevich Date: Sat, 28 Nov 1998 01:51:56 +0000 (-0500) Subject: Change $#+ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8f580fb8c3adcd8061f0e72f718bbf4ff930d697;p=p5sagit%2Fp5-mst-13.2.git Change $#+ Message-Id: <199811280651.BAA18095@monk.mps.ohio-state.edu> p4raw-id: //depot/perl@2373 --- diff --git a/mg.c b/mg.c index e960c93..ba90227 100644 --- a/mg.c +++ b/mg.c @@ -326,8 +326,13 @@ magic_regdata_cnt(SV *sv, MAGIC *mg) register REGEXP *rx; char *t; - if (PL_curpm && (rx = PL_curpm->op_pmregexp)) - return rx->lastparen; + if (PL_curpm && (rx = PL_curpm->op_pmregexp)) { + if (mg->mg_obj) /* @+ */ + return rx->nparens; + else /* @- */ + return rx->lastparen; + } + return (U32)-1; } diff --git a/pod/perlvar.pod b/pod/perlvar.pod index 7100af5..8c6305c 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -189,13 +189,14 @@ This variable is read-only. $+[0] is the offset of the end of the last successfull match. C<$+[>IC<]> is the offset of the end of the substring matched by -I-th subpattern. +I-th subpattern, or undef if the subpattern did not match. Thus after a match against $_, $& coincides with C. Similarly, C<$>I coincides with CIC<], -$+[>I<0>C<]> if C<$-[>IC<]> is defined, and $+ conincides with -C. One can use C<$#+> to find the last -matched subgroup in the last successful match. Compare with L<"@-">. +$+[0] - $-[0]>. Similarly, C<$>I coincides with CIC<], +$+[>IC<] - $-[>IC<]> if C<$-[>IC<]> is defined, and $+ coincides with +C. One can use C<$#+> to find the number +of subgroups in the last successful match. Note the difference with +C<$#->, which is the last I subgroup. Compare with L<"@-">. =item $MULTILINE_MATCHING @@ -410,13 +411,15 @@ channel. (Mnemonic: lines_on_page - lines_printed.) $-[0] is the offset of the start of the last successfull match. C<$-[>IC<]> is the offset of the start of the substring matched by -I-th subpattern. +I-th subpattern, or undef if the subpattern did not match. Thus after a match against $_, $& coincides with C. Similarly, C<$>I coincides with CIC<], -$+[>I<0>C<]> if C<$-[>IC<]> is defined, and $+ conincides with -C. One can use C<$#-> to find the last -matched subgroup in the last successful match. Compare with L<"@+">. +$+[0] - $-[0]>. Similarly, C<$>I coincides with CIC<], +$+[>IC<] - $-[>IC<]> if C<$-[>IC<]> is defined, and $+ coincides with +C. One can use C<$#-> to find the last +matched subgroup in the last successful match. Note the difference with +C<$#+>, which is the number of subgroups in the regular expression. Compare +with L<"@+">. =item format_name HANDLE EXPR diff --git a/t/op/pat.t b/t/op/pat.t index a289fbe..7bcc196 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -4,7 +4,7 @@ # the format supported by op/regexp.t. If you want to add a test # that does fit that format, add it to op/re_tests, not here. -print "1..176\n"; +print "1..177\n"; BEGIN { chdir 't' if -d 't'; @@ -692,6 +692,11 @@ print "not " print "ok $test\n"; $test++; +/.(a)(ba*)?/; +print "#$#-..$#+\nnot " if $#+ != 2 or $#- != 1; +print "ok $test\n"; +$test++; + $str = 'abcde'; pos $str = 2;