#!/usr/bin/perl
my $var = 'TCTCATGTGAAAAACTATATCAATAATATAAAAACA';正则匹配的含义
my $count = ($var =~ s/A/#/g);
print "\$count: $count\n";
my $var2 = 'TCTCATGTGAAAAACTATATCAATAATATAAAAACA';
my @count2 = ($var2 =~ s/A/#/g);
print "\@count2: @count2\n";
my $var2_1 = 'TCTCATGTGAAAAACTATATCAATAATATAAAAACA';
my @count2_1 = $var2_1 =~ s/A/#/g;
print "\@count2_1: @count2_1\n";
my $var3 = "TCTCATGTGAAAAACTATATCAATAATATAAAAACA";
my @count3 = $var3 =~ m/A/g;
print "\@count3: @count3\n";
my $var3_1 = "TCTCATGTGAAAAACTATATCAATAATATAAAAACA";
my $count3_1 = $var3_1 =~ m/A/g;
print "\$count3_1: $count3_1\n";
my $var3_2 = "TCTCATGTGAAAAACTATATCAATAATATAAAAACA";
my $count3_2 = ($var3_2 =~ m/A/g);
print "\$count3_2: $count3_2\n";
my $var4 = "!/usr/bin/perl";
my @count4 = $var4 =~ m/\w/g;
print "\@count4: @count4\n";
#运行结果如下:
#perl count_somechar_num_in_string.pl
# $count: 19
# @count2: 19
# @count2_1: 19
# @count3: A A A A A A A A A A A A A A A A A A A
# $count3_1: 1
# $count3_2: 1
# @count4: u s r b i n p e r l
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论