erlang对行读的支持

在处理文本文件的时候,基本上是以行为单位处理,特别是unix,无数的工具和算法基于这个line.

erlang在这方面支持的也非常好,极大的方便了用户。 erlang的数据大概有4个来源,在最近的R13B02这些来源都支持行读。

1. IO比如标准输入。
io:get_line([IoDevice,] Prompt) -> Data | eof | {error,Reason}
Types:
Reads a line from the standard input (IoDevice), prompting it with Prompt.

2. port,就是unix的管道,从其他的程序读取。
open_port(PortName, PortSettings) -> port()
{line, L}
Messages are delivered on a per line basis.

3. 文件。
file:read_line(IoDevice) -> {ok, Data} | eof | {error, Reason}
%%新加入的特性
Reads a line of bytes/characters from the file referenced by IoDevice.

4.网络。

底层调用的都是这个函数解码。
decode_packet(Type,Bin,Options) -> {ok,Packet,Rest} | {more,Length} | {error,Reason}

line
A packet is a line terminated with newline. The newline character is included in the returned packet unless the line was truncated according to the option line_length.


结论:
[color=red]有了这些特性, 我等就无需自己费心费力的去分解行, 把轻松留给我们,谢谢erlang.[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值