在处理文本文件的时候,基本上是以行为单位处理,特别是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]
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]