for l in "/etc/passwd".to_path.each_line do
var fields = l.split(":")
print "name={fields[0]} uid={fields[2]}"
end
Note: the stream is automatically closed at the end of the file (see LineIterator::close_on_finish
)
last_error
is updated to contains the error information on error, and null on success.
See Reader::each_line
for details.
# Return an iterator on each line of the file
#
# ~~~
# for l in "/etc/passwd".to_path.each_line do
# var fields = l.split(":")
# print "name={fields[0]} uid={fields[2]}"
# end
# ~~~
#
# Note: the stream is automatically closed at the end of the file (see `LineIterator::close_on_finish`)
#
# `last_error` is updated to contains the error information on error, and null on success.
#
# See `Reader::each_line` for details.
fun each_line: LineIterator
do
var s = open_ro
var res = s.each_line
res.close_on_finish = true
last_error = s.last_error
return res
end
lib/core/file.nit:620,2--641,4