This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] yet another 'old' patch
[perl5.git] / t / op / my.t
CommitLineData
93a17b20
LW
1#!./perl
2
a6006777 3# $RCSfile: my.t,v $
93a17b20 4
cdaebead 5print "1..30\n";
93a17b20
LW
6
7sub foo {
8 my($a, $b) = @_;
9 my $c;
10 my $d;
11 $c = "ok 3\n";
12 $d = "ok 4\n";
dab48698
SP
13 { my($a, undef, $c) = ("ok 9\n", "not ok 10\n", "ok 10\n");
14 ($x, $y) = ($a, $c); }
93a17b20
LW
15 print $a, $b;
16 $c . $d;
17}
18
19$a = "ok 5\n";
20$b = "ok 6\n";
21$c = "ok 7\n";
22$d = "ok 8\n";
23
24print &foo("ok 1\n","ok 2\n");
25
26print $a,$b,$c,$d,$x,$y;
27
28# same thing, only with arrays and associative arrays
29
30sub foo2 {
31 my($a, @b) = @_;
32 my(@c, %d);
33 @c = "ok 13\n";
34 $d{''} = "ok 14\n";
35 { my($a,@c) = ("ok 19\n", "ok 20\n"); ($x, $y) = ($a, @c); }
36 print $a, @b;
37 $c[0] . $d{''};
38}
39
40$a = "ok 15\n";
41@b = "ok 16\n";
42@c = "ok 17\n";
43$d{''} = "ok 18\n";
44
45print &foo2("ok 11\n","ok 12\n");
46
47print $a,@b,@c,%d,$x,$y;
a6006777 48
49my $i = "outer";
50
51if (my $i = "inner") {
52 print "not " if $i ne "inner";
53}
54print "ok 21\n";
55
56if ((my $i = 1) == 0) {
57 print "not ";
58}
59else {
60 print "not" if $i != 1;
61}
62print "ok 22\n";
63
64my $j = 5;
65while (my $i = --$j) {
66 print("not "), last unless $i > 0;
67}
68continue {
69 print("not "), last unless $i > 0;
70}
71print "ok 23\n";
72
73$j = 5;
74for (my $i = 0; (my $k = $i) < $j; ++$i) {
75 print("not "), last unless $i >= 0 && $i < $j && $i == $k;
76}
77print "ok 24\n";
78print "not " if defined $k;
79print "ok 25\n";
80
81foreach my $i (26, 27) {
82 print "ok $i\n";
83}
84
85print "not " if $i ne "outer";
86print "ok 28\n";
cdaebead
MB
87
88# Ensure that C<my @y> (without parens) doesn't force scalar context.
89my @x;
90{ @x = my @y }
91print +(@x ? "not " : ""), "ok 29\n";
92{ @x = my %y }
93print +(@x ? "not " : ""), "ok 30\n";
94