行ごとに操作する必要のあるテキストファイルがあります。だから私は、各ファイルを操作することができます例外を使用してファイルの行にわたる繰り返しを中断する
let withFile fn handle =
let rec iter_lines fh =
try
handle (input_line fh);
iter_lines fh
with _ -> close_in fh in
iter_lines (open_in fn);;
を:私は以下のようにwithFile
機能を書いた
withFile "file1.txt" (fun line -> (*...*))
withFile "file2.txt" (fun line -> (*...*))
...
しかし、私は私がすべての行を処理したくない場合にエレガントに終了するかどうかはわかりません。例:
withFile "file3.txt" (fun line ->
(*when the line meets some condition, i will exit without handling other lines*)
);
ご了承ください。