-{% highlight perl6 tio=https://tio.run/##K0gtyjH7/7@4NEkhOb80r0QXyCouKcrMS1fQUIEwdBRUgIK6EI6mQjWXAhDkViqogDUo2CoYWHOBxdLyixTioJr0kjMSi4qhikEAolpbWyEzTQGmBmKXhko8ihUQrZoKqYXIotZgk2ohNkEMs@aq/Y/maA0VLU8/vfTUEqCJUJamXnFi5X9HJ2cXIOQCYgA %}
+{% highlight perl6 tio=https://tio.run/##K0gtyjH7/7@4NEkhOb80r0QXyCouKcrMS1fQUIEwdBRUgIK6EI6mQjUXZ2pOam6xAlRaoa5OIdcqv0wfSZU@V@1/NOM0VLQ8/fTSU0uAxkFZmnrFiZX/HZ2cXYCQC4gB %}
sub count-substring ($string, $sub-string) {
- my $count = 0;
-
- for ^$string.chars {
- $count++ if $string.substr($_, $sub-string.chars) eq $sub-string;
- }
-
- $count;
+ elems $string ~~ m:overlap/$sub-string/
}
{% endhighlight %}
@@ -273,11 +267,10 @@ sub count-substring ($string, $sub-string) {
--
cgit v1.1