suve

awful: function: f-read

Available since rev.36 (v.0.5.0).

Declaration

NIL :f-read ( file $FILE , mixed &ARG , … )

Summary

Takes a file, followed by any number of arguments. FILE should be open for reading.

Reads values from FILE and puts them into arguments received, in a left-to-right order. Numbers are read in regard to their base system. Strings are read up to the first space character (or endline). Lines are left-trimmed of whitespace.

Example

# Sum numbers in a file
:set &f :f-reset s'example.txt'
:set &sum i0
:set &elem i1
 
!while :not :f-eof $f
    :f-read $f &elem
    :add &sum $elem
!done
 
:writeln s'Sum of elements: ' $sum 
:f-close $f

wikistrona zmodyfikowana 2014/0609/2316