[Chapter 3] 3.2.75 index
Author: Larry Wall, Tom Christiansen & Randal L. Schwartz
Date: 1999-07-02T01:50:44Z

#

| Chapter 3 Functions |

### 3.2.75 index

    index STR, SUBSTR, POSITION
    index STR, SUBSTR

This function returns the position of the first occurrence of `SUBSTR` in `STR`. The `POSITION`, if specified, says where to start looking. Positions are based at 0 (or whatever you've set the $[ variable to - but don't do that). If the substring is not found, the function returns one less than the base, ordinarily -1. To work your way through a string, you might say:

    $pos = -1;
    while (($pos = index($string, $lookfor, $pos)) > -1) {
        print "Found at $pos\n";
        $pos++;
    }

3.2.74 import |  | 3.2.76 int