This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 5.0 alpha 2
[perl5.git] / t / cmd / for.t
CommitLineData
8d063cd8
LW
1#!./perl
2
79072805 3# $RCSfile: for.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:09 $
8d063cd8 4
378cc40b 5print "1..7\n";
8d063cd8
LW
6
7for ($i = 0; $i <= 10; $i++) {
8 $x[$i] = $i;
9}
10$y = $x[10];
11print "#1 :$y: eq :10:\n";
12$y = join(' ', @x);
13print "#1 :$y: eq :0 1 2 3 4 5 6 7 8 9 10:\n";
14if (join(' ', @x) eq '0 1 2 3 4 5 6 7 8 9 10') {
15 print "ok 1\n";
16} else {
17 print "not ok 1\n";
18}
19
20$i = $c = 0;
21for (;;) {
22 $c++;
23 last if $i++ > 10;
24}
25if ($c == 12) {print "ok 2\n";} else {print "not ok 2\n";}
378cc40b
LW
26
27$foo = 3210;
28@ary = (1,2,3,4,5);
29foreach $foo (@ary) {
30 $foo *= 2;
31}
32if (join('',@ary) eq '246810') {print "ok 3\n";} else {print "not ok 3\n";}
33
34for (@ary) {
35 s/(.*)/ok $1\n/;
36}
37
38print $ary[1];
39
40# test for internal scratch array generation
41# this also tests that $foo was restored to 3210 after test 3
42for (split(' ','a b c d e')) {
43 $foo .= $_;
44}
a687059c 45if ($foo eq '3210abcde') {print "ok 5\n";} else {print "not ok 5 $foo\n";}
378cc40b
LW
46
47foreach $foo (("ok 6\n","ok 7\n")) {
48 print $foo;
49}