rindex
STR
,
SUBSTR
,
POSITION
rindex
STR
,
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 not found. Since
$[
is almost
always
0
nowadays, the function almost always returns -1.
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) {
print "Found at $pos\n";
$pos--;
}