index
examples/index.pl
use strict; use warnings; use 5.010; my $str = "The black cat climbed the green tree"; say index $str, 'cat'; # 10 say index $str, 'dog'; # -1 say index $str, "The"; # 0 say index $str, "the"; # 22
It will search for the location of the second string in the first string. Returns -1 in case the string could not find the second string. You can also add a 3rd parameter that will tell index where to start the serach from.
It is like the rindex function but starts searching from the left-hand side of the string. See also the explanation in String functions: length, lc, uc, index, substr.
Published on 2020-05-16
If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub.
Comment on this post