Monday, June 17, 2019

Perl: Count the appearance of a specific character in a string


For example, to count the appearance of character ':' in a string --

my $str = "a:b:c:d:e:f:g";
my $count = ($str =~ tr/://);
print $count, "\n";

The output will be 6.

No comments:

 
Get This <