Erlang:解释一段代码
有人能帮我理解这段Erlang代码吗Erlang:解释一段代码,erlang,Erlang,有人能帮我理解这段Erlang代码吗 to_price_file(Line, OutputFile) -> Fields = csv:parse_line(Line), [SupplierID, ProductCode, Description, DeliveryDate, CostPrice, UnitCount] = Fields, Product = calculate_product(list_to_integer(SupplierID),list_to_integer
to_price_file(Line, OutputFile) ->
Fields = csv:parse_line(Line),
[SupplierID, ProductCode, Description, DeliveryDate, CostPrice, UnitCount] = Fields,
Product = calculate_product(list_to_integer(SupplierID),list_to_integer(ProductCode),
Description, **date_utils:parse_date(DeliveryDate)**,
list_to_integer(CostPrice), list_to_integer(UnitCount)),
ok = write_pricefile(Product, OutputFile),
ok.
另一个子函数parse_date(如下)被调用
parse_date(DateString) ->
Tokens = string:tokens(DateString, "/"),
**[Year, Month, Day] = [list_to_integer(Str) || Str <- Tokens],
{Year, Month, Day}.**
parse_date(日期字符串)->
令牌=字符串:令牌(日期字符串“/”,
**[Year,Month,Day]=[list_to_integer(Str)| | Str函数parse_date/1
假设日期字符串的格式为“Year/Month/Day”
:
列表理解非常常见,通常是一种非常简洁的方法,用于将操作应用于列表中的每个元素,如lists:map/2
,带有过滤选项(此处不使用)
请注意,在ISO标准中,日期应写为2013-03-08:-函数parse_date/1
假定日期字符串的格式为“年/月/日”
:
列表理解非常常见,通常是一种非常简洁的方法,用于将操作应用于列表中的每个元素,如lists:map/2
,带有过滤选项(此处不使用)
请注意,在ISO标准中,日期应写为2013-03-08.:-)
parse_date(DateString) ->
Tokens = string:tokens(DateString, "/"),
[Year, Month, Day] = [list_to_integer(Str) || Str <- Tokens],
{Year, Month, Day}.
DateString = "2013/03/08"
Tokens = ["2013","03","08"]
[Year,Month,Date] = [2013,3,8]
{2013,3,8}