Count occurrences of a substring: Difference between revisions

(→‎{{header|Perl}}: don't apologize for not handling metachars when you can just handle 'em :))
(→‎{{header|Perl}}: add Perl 6)
Line 47:
print countSubstring("the three truths","th"), "\n";
print countSubstring("ababababab","abab"), "\n";</lang>
=={{header|Perl 6}}==
<lang perl6>sub count-substring($big,$little) { +$big.match: /$little/, :g }
 
say count-substring("the three truths","th");
say count-substring("ababababab","abab");</lang>
Note that in Perl 6 the <tt>/$little/</tt> matches the variable literally, so there's no need to quote regex metacharacters.
 
=={{header|PureBasic}}==
Anonymous user