标题: 读取一篇英文文章将所有的单词设定为键然后赋值为1创建哈希表 [打印本页] 作者: 大山里出来的孩子 时间: 2016-08-04 17:28 标题: 读取一篇英文文章将所有的单词设定为键然后赋值为1创建哈希表 刚开始的思路是:
将整个文件读取,然后按照空格切割后保存于数组中,然后遍历数组创建哈希表。但是如果文章很长,并且有多个文章的话,
先保存数组有点不太妥,效率太低,请问如何改进,使得当读入文件的时候不创建临时数组直接创建哈希表呢?
text_in:
The U.N. Food and Agriculture Organization says it has less than half the funding it needs to help ensure food security in parts of South Sudan.
.......
(太多先不贴出来了,假设文本很规范)
$ perl words.pl text_in
the half ensure of needs has Sudan. Food Agriculture to funding less in help says Organization it South than U.N. food parts security and The