14 { my($a, undef, $c) = ("ok 9\n", "not ok 10\n", "ok 10\n");
15 ($x, $y) = ($a, $c); }
16 is($a, "ok 1\n", 'value of sub argument maintained outside of block');
17 is($b, "ok 2\n", 'sub argument maintained');
18 is($c, "ok 3\n", 'variable value maintained outside of block');
19 is($d, "ok 4\n", 'variable value maintained');
27 &foo("ok 1\n","ok 2\n");
29 is($a, "ok 5\n", 'global was not affected by duplicate names inside subroutine');
30 is($b, "ok 6\n", '...');
31 is($c, "ok 7\n", '...');
32 is($d, "ok 8\n", '...');
33 is($x, "ok 9\n", 'globals modified inside of block keeps its value outside of block');
34 is($y, "ok 10\n", '...');
36 # same thing, only with arrays and associative arrays
43 { my($a,@c) = ("ok 19\n", "ok 20\n", "ok 21\n"); ($x, $y) = ($a, @c); }
44 is($a, "ok 11\n", 'value of sub argument maintained outside of block');
45 is(scalar @b, 1, 'did not add any elements to @b');
46 is($b[0], "ok 12\n", 'did not alter @b');
47 is(scalar @c, 1, 'did not add arguments to @c');
48 is($c[0], "ok 13\n", 'did not alter @c');
49 is($d{''}, "ok 14\n", 'did not touch %d');
57 &foo2("ok 11\n", "ok 12\n");
59 is($a, "ok 15\n", 'Global was not modifed out of scope');
60 is(scalar @b, 1, 'correct number of elements in array');
61 is($b[0], "ok 16\n", 'array value was not modified out of scope');
62 is(scalar @c, 1, 'correct number of elements in array');
63 is($c[0], "ok 17\n", 'array value was not modified out of scope');
64 is($d{''}, "ok 18\n", 'hash key/value pair is correct');
65 is($x, "ok 19\n", 'global was modified');
66 is($y, "ok 20\n", 'this one too');
70 if (my $i = "inner") {
71 is( $i, 'inner', 'my variable inside conditional propagates inside block');
74 if ((my $i = 1) == 0) {
75 fail("nested parens do not propagate variable outside");
78 is($i, 1, 'lexical variable lives available inside else block');
82 while (my $i = --$j) {
83 last unless is( $i, $j, 'lexical inside while block');
86 last unless is( $i, $j, 'lexical inside continue block');
88 is( $j, 0, 'went through the previous while/continue loop all 4 times' );
91 for (my $i = 0; (my $k = $i) < $j; ++$i) {
92 fail(""), last unless $i >= 0 && $i < $j && $i == $k;
94 ok( ! defined $k, '$k is only defined in the scope of the previous for loop' );
98 foreach my $i (30, 31) {
99 is( $i, $jj+30, 'assignment inside the foreach loop variable definition');
102 is( $jj, 2, 'foreach loop executed twice');
104 is( $i, 'outer', '$i not modified by while/for/foreach using same variable name');
106 # Ensure that C<my @y> (without parens) doesn't force scalar context.
109 is(scalar @x, 0, 'my @y without parens does not force scalar context');
111 is(scalar @x, 0, 'my %y without parens does not force scalar context');
113 # Found in HTML::FormatPS
114 my %fonts = qw(nok 35);
115 for my $full (keys %fonts) {
117 is( $fonts{nok}, 35, 'Supposed to be copy-on-write via force_normal after a THINKFIRST check.' );
120 # [perl #29340] optimising away the = () left the padav returning the
121 # array rather than the contents, leading to 'Bizarre copy of array' error
123 sub opta { my @a=() }
124 sub opth { my %h=() }
125 eval { my $x = opta };
126 is($@, '', ' perl #29340, No bizarre copy of array error');
127 eval { my $x = opth };
128 is($@, '', ' perl #29340, No bizarre copy of array error via hash');
132 ok(! defined $x->{bar}, '$x->{bar} is not defined');
135 eval { foo3(); foo3(); };
136 is( $@, '', 'no errors while checking autovivification and persistence of hash refs inside subs' );
138 # my $foo = undef should always assign [perl #37776]
143 is($test, undef, 'var is undef, repeated test');
145 goto loop if ++$count < 37;
150 is( $@, '', "eval of my() passes");
152 #Variable number of tests due to the way the while/for loops are tested now