in reply to Counting SubStrings, Style Question
Update:Corrected per jwkrahn's reply.
If scalar @count is greater than 2, then there must be more than one copy of substring in parent. If it is 2, there is just one. If it is zero one, it doesn't appear.
Update: To clarify per /msg, this is equivalent:
my $substring = 'xxx'; my $parent = 'xxx xxx xxx'; my @count = split($substring,$parent); my $total = scalar @count; print "there are $total $substring in $parent\n"; if( $total == 1 ) { print "None\n"; } elsif( $total == 2 ) { print "Unique\n" } else { print "Duplicates\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Counting SubStrings, Style Question
by jwkrahn (Abbot) on Mar 20, 2010 at 20:58 UTC |