Programming Perl

Programming PerlSearch this book
Previous: 3.2.127 rewinddirChapter 3
Functions
Next: 3.2.129 rmdir
 

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


Previous: 3.2.127 rewinddirProgramming PerlNext: 3.2.129 rmdir
3.2.127 rewinddirBook Index3.2.129 rmdir



Banner.Novgorod.Ru