[英]Segmentation fault error in a program for counting no of occurences of a word in a file using threads
[英]Counting word occurences from an external file and display them using Erlang?
我無法完全理解如何計算元素在文本文件中出現的次數。 我可以像這樣讀取文件-
-module(list3).
-export([readlines/1]).
readlines(FileName) ->
{ok, Device} = file:open(FileName, [read]),
try get_all_lines(Device)
after file:close(Device)
end.
get_all_lines(Device) ->
case io:get_line(Device, "") of
eof -> [];
Line -> Line ++ get_all_lines(Device)
end.
我會將文本文件傳輸到字符串列表中,並且我了解list:length或foldl通常會計算列表中元素的數量,從而返回總的單詞數,但是,我想在列表中列出單詞文件以及發生了多少次。 是否可以通過模式匹配來完成? 我目前能想到的唯一解決方案將需要大量代碼。
任何提示將不勝感激。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.