我有一個散列與各種關鍵字。現在,我想查找字符串中這些關鍵字的計數。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。 –