/^(.*?)(?:, \1)*\z/; my $count = (length($_)+2)/(length($1)+2);
for ( '1, 2, 5, 1, 2, 5, 1, 2, 5', '3, 6, 3, 6, 3, 6, 3, 6', '4, 1, 28, 0, 4, 1, 28, 0', '3, 5, 17, 3, 17, 5', '4, 1, 28, 0, 4, 1, 28', ) { for (my $seq = $_) { /^(.*?)(?:, \1)*\z/; my $count = (length($_)+2)/(length($1)+2); print("$_: $count\n"); } }
Note that this outputs the correct number of occurrences (one) for the last two inputs, not zero as the OP stated.
In reply to Re: Count occurrences of a pattern
by ikegami
in thread PLEADE HELP ME!![NEWBIE]
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |