Search⌘ K

Challenge: Check Substring

Explore how to verify if a specific substring exists within a larger string in Perl. Learn to apply built-in string functions to return precise results, enhancing your understanding of string manipulation and conditional logic in Perl programming.

Problem statement

In this challenge, you have to write code that checks if a string contains a specific string. Your code should return 1 if it does else return -1.

Sample input

The quick brown fox jumps over the lazy dog.

Check whether the said string contains the string jumps.

Sample output

1

Hint: Use the built-in functions you learned about in the previous lesson.

Important Note: Your code needs to pass all three test cases in order to be considered correct.

Coding challenge

Perl
sub stringCheck{
# try to access strings using @_[0] and @_[1]
# You have to check if the string $str2 exists in string $str1
# write your code here
return 0;
}