The [file->forEach] method takes a block of code that will be executed for each character or line in the file the [file] object refers to depending on which the get mode is set to. Inside the block you can access the current line using the special local variable #1 which will be a byte stream containing a line from the file.
local(f) = file(...)
#f->forEach => {
#1
}
The code below will output the contents of a Lasso source file as an ordered list. The default get mode is to read characters at a time instead of lines, so it is necessary for me to set the get mode specifically to reading lines in the [file]
creator method below.
Code
local(my_file) = file('index.lasso', io_file_o_rdonly, file_modeline)
handle => {#my_file->close}
'<ol>'
#my_file->forEachLine => {^
'<li>' + string(#1)->encodehtml + '</li>'
^}
'</ol>'
Result
- <?=
- library_once('/_config/conf.lasso')
- date
- ?>
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft
Recent Comments