3 # $RCSfile: substr.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:31 $
9 print (substr($a,0,3) eq 'abc' ? "ok 1\n" : "not ok 1\n");
10 print (substr($a,3,3) eq 'def' ? "ok 2\n" : "not ok 2\n");
11 print (substr($a,6,999) eq 'xyz' ? "ok 3\n" : "not ok 3\n");
12 print (substr($a,999,999) eq '' ? "ok 4\n" : "not ok 4\n");
13 print (substr($a,0,-6) eq 'abc' ? "ok 5\n" : "not ok 5\n");
14 print (substr($a,-3,1) eq 'x' ? "ok 6\n" : "not ok 6\n");
18 print (substr($a,1,3) eq 'abc' ? "ok 7\n" : "not ok 7\n");
19 print (substr($a,4,3) eq 'def' ? "ok 8\n" : "not ok 8\n");
20 print (substr($a,7,999) eq 'xyz' ? "ok 9\n" : "not ok 9\n");
21 print (substr($a,999,999) eq '' ? "ok 10\n" : "not ok 10\n");
22 print (substr($a,1,-6) eq 'abc' ? "ok 11\n" : "not ok 11\n");
23 print (substr($a,-3,1) eq 'x' ? "ok 12\n" : "not ok 12\n");
27 substr($a,3,3) = 'XYZ';
28 print $a eq 'abcXYZxyz' ? "ok 13\n" : "not ok 13\n";
30 print $a eq 'cXYZxyz' ? "ok 14\n" : "not ok 14\n";
32 substr($a,0,0) = 'ab';
33 print $a eq 'abcXYZxyz' ? "ok 15\n" : "not ok 15 $a\n";
34 substr($a,0,0) = '12345678';
35 print $a eq '12345678abcXYZxyz' ? "ok 16\n" : "not ok 16\n";
36 substr($a,-3,3) = 'def';
37 print $a eq '12345678abcXYZdef' ? "ok 17\n" : "not ok 17\n";
38 substr($a,-3,3) = '<';
39 print $a eq '12345678abcXYZ<' ? "ok 18\n" : "not ok 18\n";
40 substr($a,-1,1) = '12345678';
41 print $a eq '12345678abcXYZ12345678' ? "ok 19\n" : "not ok 19\n";
45 print (substr($a,6) eq 'xyz' ? "ok 20\n" : "not ok 20\n");
46 print (substr($a,-3) eq 'xyz' ? "ok 21\n" : "not ok 21\n");
47 print (substr($a,999) eq '' ? "ok 22\n" : "not ok 22\n");
49 # with lexicals (and in re-entered scopes)
54 substr($txt, -1) = "X";
55 print $txt eq "FoX" ? "ok 23\n" : "not ok 23\n";
58 substr($txt, 0, 1) = "X";
59 print $txt eq "X" ? "ok 24\n" : "not ok 24\n";
63 # coersion of references
66 substr($s, 0, 1) = 'Foo';
67 print substr($s,0,7) eq "FooRRAY" ? "ok 25\n" : "not ok 25\n";