Hi, <br><br>I have just started learning Erlang by myself and came across this. I searched for this in the past questions, but I was not able to find anything that might be related this. So please let me ask about this. I am using R13B on Windows. But this also occurred on Linux. <br>
<br>I wrote fragments of code that read a file and print its content like the following. <br><br>----------<br><br>-module(rw).<br><br>-export([for_each_line/4, print/3, main/1]).<br><br>for_each_line(Filename, [_, {encoding, Encoding}]=Mode, F, Args) -><br>
case file:open(Filename, Mode) of<br> {ok, Device} -><br> F(Device, Encoding, Args);<br> {error, Reason} -><br> erlang:error(Reason)<br> end.<br><br>print(Device, Encoding, Args) -><br>
case io:get_line(Device, "") of<br> {error, Reason} -><br> erlang:error(Reason),<br> file:close(Device);<br> eof -><br> file:close(Device);<br> Data -><br>
io:format("~s~n", [unicode:characters_to_binary(Data, Encoding)]),<br> print(Device, Encoding, Args)<br> end.<br><br>main(Args) -><br> [Filename] = Args,<br> for_each_line(Filename, [read, {encoding, utf8}], fun rw:print/3, []).<br>
<br>------------<br><br>I made files encoded in utf-8 and tried to print its content. This worked fine to some extent. <br>However, when I tried to read files that contained Japanese characters, I got an error saying that<br>
<br>------------<br><br>$ erl -noshell -s rw main test.txt<br>{"init terminating in do_boot",{collect_line,[{rw,print,3},{init,start_it,1},{init,start_em,1}]}}<br><br>Crash dump was written to: erl_crash.dump<br>
init terminating in do_boot ()<br><br>------------<br><br>After I looked into this for a while, I found that it seemed that if a line started with three consecutive ASCII characters following some Japanese characters, this error could occur. <br>
For example, <br><br>..ほげほげ,ほげほげ,ほげほげ,ほげほげ,ほげほげ,,,ほげほげ,,ほげほげ,ほげほげ,ほげほげ,ほげほげ,ほげほげ,,,<br><br>which starts with two dots following Japanese characters, was ok. But <br><br>...ほげほげ,ほげほげ,ほげほげ,ほげほげ,ほげほげ,,,ほげほげ,,ほげほげ,ほげほげ,ほげほげ,ほげほげ,ほげほげ,,,<br>
<br>where a dot "." was added at the head of the line, got the error. <br><br>If my code has some problem, which might be so more likely, please advise me. <br>Please let me know if there is someone who has come across something similar to this. <br>
<br>I will post the dump file later if necessary. <br><br>Best regards. <br><br>Chiharu<br><br><br><br>