February 2012
Intermediate to advanced
1184 pages
37h 17m
English
rindexSTR,SUBSTR,POSITIONrindexSTR,SUBSTR
This function works just like index except that it returns the position of
the last occurrence of
SUBSTR in STR (a
reverse index). The function returns
–1 if
SUBSTR is not found.
POSITION, if specified, is the rightmost
position that may be returned. To work your way through a string
backward, say:
$pos = length $string;
while (($pos = rindex $string, $lookfor, $pos) >= 0) {
say "Found at $pos";
$pos––;
}Note that like index, this works by character (codepoint)
position, not by grapheme
position. To work with strings as sequences of graphemes instead of
codepoints, see the
index, rindex, and pos methods for the CPAN Unicode :: GCString module.
Read now
Unlock full access