in reply to Re^2: Counting SubStrings, Style Question
in thread Counting SubStrings, Style Question
for my $count (0..4) { print("$count: "); if ($count < 1) { print "None\n"; } elsif ($count < 2) { print "Unique\n"; } else { print "$count\n"; } }
Or using your examples0: None 1: Unique 2: 2 3: 3 4: 4
my $substr = 'xxx'; for my $parent ( 'fred bill xx joe', 'fred bill xxx joe', ) { my $count = () = $parent =~ /\Q$substr/; if ($count < 1) { print "None\n"; } elsif ($count < 2) { print "Unique\n"; } else { print "$count\n"; } }
None Unique
It's the count is wrong. My entire post is about how split is not the right tool here because it can give the wrong count. That's why my solution doesn't use split.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Counting SubStrings, Style Question
by Anonymous Monk on Mar 21, 2010 at 00:38 UTC | |
by ikegami (Patriarch) on Mar 21, 2010 at 05:09 UTC |