This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl 3.0: (no announcement message available)
[perl5.git] / t / op.array
CommitLineData
a687059c
LW
1#!./perl
2
3# $Header: op.array,v 3.0 89/10/18 15:26:55 lwall Locked $
4
5print "1..30\n";
6
7@ary = (1,2,3,4,5);
8if (join('',@ary) eq '12345') {print "ok 1\n";} else {print "not ok 1\n";}
9
10$tmp = $ary[$#ary]; --$#ary;
11if ($tmp == 5) {print "ok 2\n";} else {print "not ok 2\n";}
12if ($#ary == 3) {print "ok 3\n";} else {print "not ok 3\n";}
13if (join('',@ary) eq '1234') {print "ok 4\n";} else {print "not ok 4\n";}
14
15$[ = 1;
16@ary = (1,2,3,4,5);
17if (join('',@ary) eq '12345') {print "ok 5\n";} else {print "not ok 5\n";}
18
19$tmp = $ary[$#ary]; --$#ary;
20if ($tmp == 5) {print "ok 6\n";} else {print "not ok 6\n";}
21if ($#ary == 4) {print "ok 7\n";} else {print "not ok 7\n";}
22if (join('',@ary) eq '1234') {print "ok 8\n";} else {print "not ok 8\n";}
23
24if ($ary[5] eq '') {print "ok 9\n";} else {print "not ok 9\n";}
25
26$#ary += 1; # see if we can recover element 5
27if ($#ary == 5) {print "ok 10\n";} else {print "not ok 10\n";}
28if ($ary[5] == 5) {print "ok 11\n";} else {print "not ok 11\n";}
29
30$[ = 0;
31@foo = ();
32$r = join(',', $#foo, @foo);
33if ($r eq "-1") {print "ok 12\n";} else {print "not ok 12 $r\n";}
34$foo[0] = '0';
35$r = join(',', $#foo, @foo);
36if ($r eq "0,0") {print "ok 13\n";} else {print "not ok 13 $r\n";}
37$foo[2] = '2';
38$r = join(',', $#foo, @foo);
39if ($r eq "2,0,,2") {print "ok 14\n";} else {print "not ok 14 $r\n";}
40@bar = ();
41$bar[0] = '0';
42$bar[1] = '1';
43$r = join(',', $#bar, @bar);
44if ($r eq "1,0,1") {print "ok 15\n";} else {print "not ok 15 $r\n";}
45@bar = ();
46$r = join(',', $#bar, @bar);
47if ($r eq "-1") {print "ok 16\n";} else {print "not ok 16 $r\n";}
48$bar[0] = '0';
49$r = join(',', $#bar, @bar);
50if ($r eq "0,0") {print "ok 17\n";} else {print "not ok 17 $r\n";}
51$bar[2] = '2';
52$r = join(',', $#bar, @bar);
53if ($r eq "2,0,,2") {print "ok 18\n";} else {print "not ok 18 $r\n";}
54reset 'b';
55@bar = ();
56$bar[0] = '0';
57$r = join(',', $#bar, @bar);
58if ($r eq "0,0") {print "ok 19\n";} else {print "not ok 19 $r\n";}
59$bar[2] = '2';
60$r = join(',', $#bar, @bar);
61if ($r eq "2,0,,2") {print "ok 20\n";} else {print "not ok 20 $r\n";}
62
63$foo = 'now is the time';
64if (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/)) {
65 if ($F1 eq 'now' && $F2 eq 'is' && $Etc eq 'the time') {
66 print "ok 21\n";
67 }
68 else {
69 print "not ok 21\n";
70 }
71}
72else {
73 print "not ok 21\n";
74}
75
76$foo = 'lskjdf';
77if ($cnt = (($F1,$F2,$Etc) = ($foo =~ /^(\S+)\s+(\S+)\s*(.*)/))) {
78 print "not ok 22 $cnt $F1:$F2:$Etc\n";
79}
80else {
81 print "ok 22\n";
82}
83
84%foo = ('blurfl','dyick','foo','bar','etc.','etc.');
85%bar = %foo;
86print $bar{'foo'} eq 'bar' ? "ok 23\n" : "not ok 23\n";
87%bar = ();
88print $bar{'foo'} eq '' ? "ok 24\n" : "not ok 24\n";
89(%bar,$a,$b) = (%foo,'how','now');
90print $bar{'foo'} eq 'bar' ? "ok 25\n" : "not ok 25\n";
91print $bar{'how'} eq 'now' ? "ok 26\n" : "not ok 26\n";
92@bar{keys %foo} = values %foo;
93print $bar{'foo'} eq 'bar' ? "ok 27\n" : "not ok 27\n";
94print $bar{'how'} eq 'now' ? "ok 28\n" : "not ok 28\n";
95
96@foo = grep(/e/,split(' ','now is the time for all good men to come to'));
97print join(' ',@foo) eq 'the time men come' ? "ok 29\n" : "not ok 29\n";
98
99@foo = grep(!/e/,split(' ','now is the time for all good men to come to'));
100print join(' ',@foo) eq 'now is for all good to to' ? "ok 30\n" : "not ok 30\n";