in reply to count number of occurrences of specific character(s) in a string
I'd write that as
sub count_separators { my $value = shift; my $delim = shift; my %map = ( '(' => '()', '{' => '{}', '"' => '"'; ); my $tr = $map{$delim} or die "Not a valid separator"; return eval "\$value =~ tr/$tr/;" }
(untested).
|
|---|