This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] merge a maint patch
[perl5.git] / t / op / local.t
CommitLineData
a687059c
LW
1#!./perl
2
79072805 3# $RCSfile: local.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:04 $
a687059c 4
301d9039 5print "1..25\n";
a687059c
LW
6
7sub foo {
8 local($a, $b) = @_;
9 local($c, $d);
10 $c = "ok 3\n";
11 $d = "ok 4\n";
12 { local($a,$c) = ("ok 9\n", "ok 10\n"); ($x, $y) = ($a, $c); }
13 print $a, $b;
14 $c . $d;
15}
16
17$a = "ok 5\n";
18$b = "ok 6\n";
19$c = "ok 7\n";
20$d = "ok 8\n";
21
93a17b20 22print &foo("ok 1\n","ok 2\n");
a687059c
LW
23
24print $a,$b,$c,$d,$x,$y;
25
26# same thing, only with arrays and associative arrays
27
28sub foo2 {
29 local($a, @b) = @_;
30 local(@c, %d);
31 @c = "ok 13\n";
32 $d{''} = "ok 14\n";
33 { local($a,@c) = ("ok 19\n", "ok 20\n"); ($x, $y) = ($a, @c); }
34 print $a, @b;
35 $c[0] . $d{''};
36}
37
38$a = "ok 15\n";
39@b = "ok 16\n";
40@c = "ok 17\n";
41$d{''} = "ok 18\n";
42
93a17b20 43print &foo2("ok 11\n","ok 12\n");
a687059c
LW
44
45print $a,@b,@c,%d,$x,$y;
706a304b
SM
46
47eval 'local($$e)';
48print +($@ =~ /Can't localize through a reference/) ? "" : "not ", "ok 21\n";
49
50eval 'local(@$e)';
51print +($@ =~ /Can't localize through a reference/) ? "" : "not ", "ok 22\n";
52
53eval 'local(%$e)';
54print +($@ =~ /Can't localize through a reference/) ? "" : "not ", "ok 23\n";
85aff577
CS
55
56# check for scope leakage
57$a = 'outer';
58if (1) { local $a = 'inner' }
59print +($a eq 'outer') ? "" : "not ", "ok 24\n";
60
301d9039
GS
61# see if localization works when scope unwinds
62
63local $m = 5;
64eval {
65 for $m (6) {
66 local $m = 7;
67 die "bye";
68 }
69};
70print $m == 5 ? "" : "not ", "ok 25\n";