Read a file line by line: Difference between revisions

Line 2,832:
if($line != NULL) echo("$line\n"); // IF THE LINE ISN'T NULL, ECHO THE LINE
}</lang>
 
=={{header|Picat}}==
 
===read_line/1===
The proper way of reading a file line by line is to use <code>read_line(FH)</code>. This is he recommended way for a very large files.
<lang Picat>go =>
FD = open("unixdict.txt"),
while (not at_end_of_stream(FD))
Line = read_line(FD),
println(Line)
end,
close(FD),
nl.</lang>
 
===read_file_lines===
For reasonable sized files, <code>read_file_lines/1</code> is usually the way to go.
<lang Picat>go2 =>
foreach(Line in read_file_lines("unixdict.txt"))
println(Line)
end.</lang>
 
 
=={{header|PicoLisp}}==
495

edits