Skip to content

Commit 1da21e2

Browse files
scottchiefbakerkhwilliamson
authored andcommitted
Update index() documentation with some code examples
1 parent 8fccc13 commit 1da21e2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pod/perlfunc.pod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3585,6 +3585,20 @@ respectively. POSITION and the return value are based at zero.
35853585
If the substring is not found, L<C<index>|/index STR,SUBSTR,POSITION>
35863586
returns -1.
35873587

3588+
Find characters or strings:
3589+
3590+
index("Perl is great", "P"); # Returns 0
3591+
index("Perl is great", "g"); # Returns 8
3592+
index("Perl is great", "great"); # Also returns 8
3593+
3594+
Attempting to find something not there:
3595+
3596+
index("Perl is great", "Z"); # Returns -1 (not found)
3597+
3598+
Using an offset to find the I<second> occurrence:
3599+
3600+
index("Perl is great", "e", 5); # Returns 10
3601+
35883602
=item int EXPR
35893603
X<int> X<integer> X<truncate> X<trunc> X<floor>
35903604

0 commit comments

Comments
 (0)