程序如下
print "Please input the name\n";chomp(@words=<STDIN>);foreach $word(@words){ $count{$word} +=1;#哈希因赋值而诞生}foreach $word(keys %count)#在这里如果写成foreach $word(sort keys %count),那么就可以对输出的信息进行排序{ print "$word was seen $count{$word} times.\n";}以下为运行结果:
F:\>perl\a.plPlease input the namegrepthank youthank youhow are youmy name sihhahha^Zthank you was seen 1 times.hha was seen 2 times.grep was seen 1 times.thank you was seen 1 times.how are you was seen 1 times.my name si was seen 1 times.总结
以上是内存溢出为你收集整理的哈希因赋值而诞生,单词个数的统计全部内容,希望文章能够帮你解决哈希因赋值而诞生,单词个数的统计所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)