1#!./perl 2 3print "1..28\n"; 4 5@foo = (1, 2, 3, 4); 6if ($foo[0] == 1 && $foo[3] == 4) {print "ok 1\n";} else {print "not ok 1\n";} 7 8$_ = join(':',@foo); 9if ($_ eq '1:2:3:4') {print "ok 2\n";} else {print "not ok 2\n";} 10 11($a,$b,$c,$d) = (1,2,3,4); 12if ("$a;$b;$c;$d" eq '1;2;3;4') {print "ok 3\n";} else {print "not ok 3\n";} 13 14($c,$b,$a) = split(/ /,"111 222 333"); 15if ("$a;$b;$c" eq '333;222;111') {print "ok 4\n";} else {print "not ok 4\n";} 16 17($a,$b,$c) = ($c,$b,$a); 18if ("$a;$b;$c" eq '111;222;333') {print "ok 5\n";} else {print "not ok 5 $a;$b;$c\n";} 19 20($a, $b) = ($b, $a); 21if ("$a;$b;$c" eq '222;111;333') {print "ok 6\n";} else {print "not ok 6\n";} 22 23($a, $b[1], $c{2}, $d) = (1, 2, 3, 4); 24if ($a eq 1) {print "ok 7\n";} else {print "not ok 7\n";} 25if ($b[1] eq 2) {print "ok 8\n";} else {print "not ok 8\n";} 26if ($c{2} eq 3) {print "ok 9\n";} else {print "not ok 9\n";} 27if ($d eq 4) {print "ok 10\n";} else {print "not ok 10\n";} 28 29@foo = (1,2,3,4,5,6,7,8); 30($a, $b, $c, $d) = @foo; 31print "#11 $a;$b;$c;$d eq 1;2;3;4\n"; 32if ("$a;$b;$c;$d" eq '1;2;3;4') {print "ok 11\n";} else {print "not ok 11\n";} 33 34@foo = @bar = (1); 35if (join(':',@foo,@bar) eq '1:1') {print "ok 12\n";} else {print "not ok 12\n";} 36 37@foo = (); 38@foo = 1+2+3; 39if (join(':',@foo) eq '6') {print "ok 13\n";} else {print "not ok 13\n";} 40 41for ($x = 0; $x < 3; $x++) { 42 ($a, $b, $c) = 43 $x == 0? 44 ('ok ', 14, "\n"): 45 $x == 1? 46 ('ok ', 15, "\n"): 47 # default 48 ('ok ', 16, "\n"); 49 50 print $a,$b,$c; 51} 52 53@a = ($x == 12345 || (1,2,3)); 54if (join('',@a) eq '123') {print "ok 17\n";} else {print "not ok 17\n";} 55 56@a = ($x == $x || (4,5,6)); 57if (join('',@a) eq '1') {print "ok 18\n";} else {print "not ok 18\n";} 58 59if (join('',1,2,(3,4,5)) eq '12345'){print "ok 19\n";}else{print "not ok 19\n";} 60if (join('',(1,2,3,4,5)) eq '12345'){print "ok 20\n";}else{print "not ok 20\n";} 61if (join('',(1,2,3,4),5) eq '12345'){print "ok 21\n";}else{print "not ok 21\n";} 62if (join('',1,(2,3,4),5) eq '12345'){print "ok 22\n";}else{print "not ok 22\n";} 63if (join('',1,2,(3,4),5) eq '12345'){print "ok 23\n";}else{print "not ok 23\n";} 64if (join('',1,2,3,(4),5) eq '12345'){print "ok 24\n";}else{print "not ok 24\n";} 65 66for ($x = 0; $x < 3; $x++) { 67 ($a, $b, $c) = do { 68 if ($x == 0) { 69 ('ok ', 25, "\n"); 70 } 71 elsif ($x == 1) { 72 ('ok ', 26, "\n"); 73 } 74 else { 75 ('ok ', 27, "\n"); 76 } 77 }; 78 79 print $a,$b,$c; 80} 81 82# slices 83{ 84 my @a = (0, undef, undef, 3); 85 my @b = @a[1,2]; 86 my @c = (0, undef, undef, 3)[1, 2]; 87 print "not " unless @b == @c and @c == 2; 88 print "ok 28\n"; 89} 90