Author: techfox9

Counting characters in perl..

Friday, August 13th, 2010 @ 12:24 am

From http://www.perlmonks.org/?node_id=63955

How many ‘a’ characters are in the string?

#!/usr/bin/perl

my $str = 'abcatpdmeuziapmb';
my $cnt = @{[$str =~ /(a)/g]};
print "$cnt\n";

Perl


 


Comments are closed.