我有一个散列与各种关键字。现在,我想查找字符串中这些关键字的计数。Perl匹配计数
我只是用foreach循环写了一部分代码。
use strict;
use warnings;
my $string = "The invitro experiments are conducted on human liver microsom. "
. " These liver microsom can be cultured in rats.";
my %hash = (
"human" => 1,
"liver" => 1,
"microsom" => 1,
);
for my $nme (keys %hash){
# Some code which I am not sure
}
预期输出:human:1; liver:2; microsom:3
有人可以帮助我在这?
谢谢
why microsom:3? '$ string'中似乎只有两处出现! – Vikdor
你应该在尝试之前[尝试](http://mattgemmell.com/2008/12/08/what-have-you-tried/)。如果你有,告诉我们你的尝试。 – m0skit0
对不起。它应该是microsom:2。 –