perl中怎样统计数组中不同长度字符串的个数
比如 @a=("A" ,"G","GC",""GCT","AT","AGCT" ,"TCGU","T" ); 长度为一个字符的是3,两个字符的是2,三个字符的是1,四个字符的是2。代码该如何写,谢谢各位大侠了!
写了一下,这样能够打印信凯茄出来:
#! /usr/bin/perl -w
use strict;
my @a=("A","G","GC","GCT","AT","AGCT"滑察,"TCGU"孙含,"T");
my @b;
my $lengths=1;
for (@a)
{
my $len=length($_);
$b[$len-1] +=1;
}
for (@b)
{
print "length$lengths:$_\n";
$lengths +=1;
}
foreach(@a){
$i=length($_);
if($length{$i}){
$length{$i}++;
}else{
$length{$i}=1;
}
}
while(($key,$value)=each %length){
print "$key char element is $value\n";
}
foreach(@a)
{
$len = length($_);
$b[$len] +=1;
}
print @b;