[Chapter 3] 3.2.128 rindex
Author: Larry Wall, Tom Christiansen & Randal L. Schwartz
Date: 1999-07-02T01:53:26Z

#

| Chapter 3 Functions |

### 3.2.128 rindex

    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--;
    }

3.2.127 rewinddir |  | 3.2.129 rmdir