Lasso Soft Inc. > Home

[ file->forEachLine ]

Method

The [file->forEachLine] method takes a block of code that will be executed for each line in the file the [file] object refers 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.

  • Syntax
local(f) = file(...)
#f->forEachLine => {
    #1
}
Examples
  • Intermediate

Display Lasso code file with line numbers

The code below will output the contents of a Lasso source file as an ordered list.

Code

local(my_file) = file('index.lasso')
handle => {#my_file->close}
'<ol>'
#my_file->forEachLine => {^
    '<li>' + string(#1)->encodehtml + '</li>'
^}
'</ol>'

Result

  1. <?=
  2. library_once('/_config/conf.lasso')
  3. date
  4. ?>

Recent Comments

No Comments found

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. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft