How can I count characters in Perl?

后端 未结 4 424
长发绾君心
长发绾君心 2021-01-11 12:09

I have the following Perl script counting the number of Fs and Ts in a string:

my $str = \"GGGFFEEIIEETTGGG\";
my $ft_count = 0;
$ft_count++ while($str =~ m/         


        
4条回答
  •  再見小時候
    2021-01-11 12:34

    You can combine line 2, 3 and 4 into one like so:

    my $str = "GGGFFEEIIEETTGGG";
    print $str =~ s/[FT]//g; #Output 4;
    

提交回复
热议问题