@a = qw /hehe haha zz 123 456 && hehe/;
$count{$_}++ foreach @a ;
foreach $word (sort @a){
print "$word has been appreared $count{$word} times! \n"
}
运行程序:
root@luis-VirtualBox:~# ./perl.pl
&& has been appreared 1 times!
123 has been appreared 1 times!
456 has been appreared 1 times!
haha has been appreared 1 times!
hehe has been appreared 2 times!
hehe has been appreared 2 times!
zz has been appreared 1 times!
那个hehe打印了两次,我不想要重复输出,能不能修改程序只打印一次hehe ? (保持@a中的两个hehe别动)