- Perl Basics
- Perl - Home
- Perl - Introduction
- Perl - Environment
- Perl - Syntax Overview
- Perl - Data Types
- Perl - Variables
- Perl - Scalars
- Perl - Arrays
- Perl - Hashes
- Perl - IF...ELSE
- Perl - Loops
- Perl - Operators
- Perl - Date & Time
- Perl - Subroutines
- Perl - References
- Perl - Formats
- Perl - File I/O
- Perl - Directories
- Perl - Error Handling
- Perl - Special Variables
- Perl - Coding Standard
- Perl - Regular Expressions
- Perl - Sending Email
- Perl Advanced
- Perl - Socket Programming
- Perl - Object Oriented
- Perl - Database Access
- Perl - CGI Programming
- Perl - Packages & Modules
- Perl - Process Management
- Perl - Embedded Documentation
- Perl - Functions References
- Perl Useful Resources
- Perl - Questions and Answers
- Perl - Quick Guide
- Perl - Useful Resources
- Perl - Discussion
Perl rindex Function
Description
This function 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.
Syntax
Following is the simple syntax for this function −
rindex STR, SUBSTR, POSITION rindex STR, SUBSTR
Return Value
This function returns undef on failure otherwise position of last occurence.
Example
Following is the example code showing its basic usage −
#!/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";
When above code is executed, it produces the following result −
Found position of def 14 Found position of def 3
perl_function_references.htm
Advertisements