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
2.1m questions
2.1m answers
60 comments
57.0k users