Syntax
rindex STR, SUBSTR, POSITION
rindex STR, SUBSTR
|
Definition and Usage
Operates similar to index, except it returns the position of the last occurrence of SUBSTR in STR. If POSITION is specified, returns the last occurrence at or before that position.
Return Value
Example
Try out following example:
#!/usr/bin/perl -w
$pos = rindex("abcdefghijiklmdef", "def");
print "Found position of def $pos\n";
# Use the first position found as the offset to the
# next search.
# Note that the length of the target string is
# subtracted from the offset to save time.
$pos = rindex("abcdefghijiklmdef", "def", $pos-3 );
print "Found position of def $pos\n";
|
It will produce following results:
Found position of def 14
Found position of def 3
| |
|