From: Gurusamy Sarathy Date: Sun, 19 Jul 1998 01:21:22 +0000 (+0000) Subject: make failed matches return empty list in list context X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f7e33566f09bd09e2a30db0e6835322b7f19bbd2;p=p5sagit%2Fp5-mst-13.2.git make failed matches return empty list in list context p4raw-id: //depot/perl@1542 --- diff --git a/pod/perlop.pod b/pod/perlop.pod index 8b73629..c7209fa 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -774,11 +774,11 @@ I matched regular expression is used instead. If the C option is not used, C in a list context returns a list consisting of the subexpressions matched by the parentheses in the -pattern, i.e., (C<$1>, C<$2>, C<$3>...). (Note that here -C<$1> etc. are also set, and -that this differs from Perl 4's behavior.) If there are no parentheses, -the return value is the list C<(1)> for success or C<('')> upon failure. -With parentheses, C<()> is returned upon failure. +pattern, i.e., (C<$1>, C<$2>, C<$3>...). (Note that here C<$1> etc. are +also set, and that this differs from Perl 4's behavior.) When there are +no parentheses in the pattern, the return value is the list C<(1)> for +success. With or without parentheses, an empty list is returned upon +failure. Examples: diff --git a/pp_hot.c b/pp_hot.c index 4fe40cc..3ecb5b3 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -853,8 +853,6 @@ PP(pp_match) } } } - if (!rx->nparens && !global) - gimme = G_SCALAR; /* accidental array context? */ safebase = (((gimme == G_ARRAY) || global || !rx->nparens) && !sawampersand); safebase = safebase ? 0 : REXEC_COPY_STR ; @@ -958,6 +956,8 @@ play_it_again: PUTBACK; /* EVAL blocks may use stack */ goto play_it_again; } + else if (!iters) + XPUSHs(&sv_yes); LEAVE_SCOPE(oldsave); RETURN; } diff --git a/t/op/pat.t b/t/op/pat.t index cbd5f89..ef014f2 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -4,9 +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. -# $RCSfile: pat.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:12 $ - -print "1..135\n"; +print "1..139\n"; BEGIN { chdir 't' if -d 't'; @@ -560,3 +558,26 @@ my $for_future = make_must_warn('reserved for future extensions'); &$for_future('q(a:[b]:) =~ /[x[:foo:]]/'); &$for_future('q(a=[b]=) =~ /[x[=foo=]]/'); &$for_future('q(a.[b].) =~ /[x[.foo.]]/'); + +# test if failure of patterns returns empty list +$_ = 'aaa'; +@_ = /bbb/; +print "not " if @_; +print "ok $test\n"; +$test++; + +@_ = /bbb/g; +print "not " if @_; +print "ok $test\n"; +$test++; + +@_ = /(bbb)/; +print "not " if @_; +print "ok $test\n"; +$test++; + +@_ = /(bbb)/g; +print "not " if @_; +print "ok $test\n"; +$test++; +