summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1998-09-18 18:01:37 +0000
committerGurusamy Sarathy <gsar@cpan.org>1998-09-18 18:01:37 +0000
commit8bb77e1d87aec5c3f7c4bf32f677921213e0f7bd (patch)
treef7bde236f2c1e451fefb8b9fca0fdf7a4530f779
parent0f61463b175e361f082ecc967a3f67bf2fb0e62d (diff)
downloadperl-8bb77e1d87aec5c3f7c4bf32f677921213e0f7bd.tar.gz
delay freeing itervar so C<for $i (@a) { return($i) }> works
p4raw-id: //depot/perl@1789
-rw-r--r--cop.h2
-rwxr-xr-xt/cmd/for.t14
2 files changed, 12 insertions, 4 deletions
diff --git a/cop.h b/cop.h
index 4d020196cd..f15b1e125d 100644
--- a/cop.h
+++ b/cop.h
@@ -143,7 +143,7 @@ struct block_loop {
#define POPLOOP2() \
SvREFCNT_dec(cxloop.iterlval); \
if (cxloop.itervar) { \
- SvREFCNT_dec(*cxloop.itervar); \
+ sv_2mortal(*cxloop.itervar); \
*cxloop.itervar = cxloop.itersave; \
} \
if (cxloop.iterary && cxloop.iterary != PL_curstack) \
diff --git a/t/cmd/for.t b/t/cmd/for.t
index e45f05040b..d70af579fc 100755
--- a/t/cmd/for.t
+++ b/t/cmd/for.t
@@ -1,8 +1,6 @@
#!./perl
-# $RCSfile: for.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:09 $
-
-print "1..7\n";
+print "1..10\n";
for ($i = 0; $i <= 10; $i++) {
$x[$i] = $i;
@@ -47,3 +45,13 @@ if ($foo eq '3210abcde') {print "ok 5\n";} else {print "not ok 5 $foo\n";}
foreach $foo (("ok 6\n","ok 7\n")) {
print $foo;
}
+
+sub foo {
+ for $i (1..5) {
+ return $i if $_[0] == $i;
+ }
+}
+
+print foo(1) == 1 ? "ok" : "not ok", " 8\n";
+print foo(2) == 2 ? "ok" : "not ok", " 9\n";
+print foo(5) == 5 ? "ok" : "not ok", " 10\n";