11 $foo = 'Now is the time for all good men to come to the aid of their country.';
13 $first = substr($foo,0,index($foo,'the'));
14 is($first, "Now is ");
16 $last = substr($foo,rindex($foo,'the'),100);
17 is($last, "their country.");
19 $last = substr($foo,index($foo,'Now'),2);
22 $last = substr($foo,rindex($foo,'Now'),2);
25 $last = substr($foo,index($foo,'.'),100);
28 $last = substr($foo,rindex($foo,'.'),100);
31 is(index("ababa","a",-1), 0);
32 is(index("ababa","a",0), 0);
33 is(index("ababa","a",1), 2);
34 is(index("ababa","a",2), 2);
35 is(index("ababa","a",3), 4);
36 is(index("ababa","a",4), 4);
37 is(index("ababa","a",5), -1);
39 is(rindex("ababa","a",-1), -1);
40 is(rindex("ababa","a",0), 0);
41 is(rindex("ababa","a",1), 0);
42 is(rindex("ababa","a",2), 2);
43 is(rindex("ababa","a",3), 2);
44 is(rindex("ababa","a",4), 4);
45 is(rindex("ababa","a",5), 4);
47 $a = "foo \x{1234}bar";
49 is(index($a, "\x{1234}"), 4);
50 is(index($a, "bar", ), 5);
52 is(rindex($a, "\x{1234}"), 4);
53 is(rindex($a, "foo", ), 0);
56 my $needle = "\x{1230}\x{1270}";
57 my @needles = split ( //, $needle );
58 my $haystack = "\x{1228}\x{1228}\x{1230}\x{1270}";
59 foreach ( @needles ) {
60 my $a = index ( "\x{1228}\x{1228}\x{1230}\x{1270}", $_ );
61 my $b = index ( $haystack, $_ );
62 is($a, $b, q{[perl #22375] 'split'/'index' problem for utf8});
64 $needle = "\x{1270}\x{1230}"; # Transpose them.
65 @needles = split ( //, $needle );
66 foreach ( @needles ) {
67 my $a = index ( "\x{1228}\x{1228}\x{1230}\x{1270}", $_ );
68 my $b = index ( $haystack, $_ );
69 is($a, $b, q{[perl #22375] 'split'/'index' problem for utf8});