How can I check whether a given string contains a certain substring, using Perl?
More specifically, I want to see whether s1.domain.com is present in the given string variable.
s1.domain.com
To find out if a string contains substring you can use the index function:
index
if (index($str, $substr) != -1) { print "$str contains $substr "; }
It will return the position of the first occurrence of $substr in $str, or -1 if the substring is not found.
$substr
$str
1.4m articles
1.4m replys
5 comments
57.0k users