use strict; use warnings; my $substring = 'xxx'; my $parent = 'xxx xxx xxx'; my @count = split($substring,$parent); my $total = $#count + 1; print "there are $total $substring in $parent\n"; if($parent =~ /$substring[\s\S]*$substring/) { print "Duplicates\n" } elsif( $parent !~ /$substring/) { print "None\n"; } else { print "Unique\n" }
This is a style/performance question. What's the best way to count the number of items in a string and test for uniqueness? I'm not asking what it does? I'd like to know if there a better way. Thanks.
In reply to Counting SubStrings, Style Question by se@n
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |