my @chars = split //, $inp_row; my $cnt = 0; for (@chars) { $cnt++ if ($_ eq $de) }
You could eliminate the array, for loop and conditional increment by using grep.
my $cnt = grep { $_ eq $de } split m{}, $inp_row;
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^2: Regex - counting number of '|'
by johngg
in thread Regex - counting number of '|'
by perl_junkie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |