Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: alternate way to divide into lines

...

Line 1 defines the import function, which expects the entire exported file as a single string. Line 2 defines a regular expression which will match the end of a line within the string. Line 3 splits the entire content into an array of lines, each one a string. Line 4 keeps all of the lines except for the first one, which is a header line and not actual data. Finally, line 5 throws away any line which is the empty string (there will be one such after the last newline sequence in the data file), using the fact that KRL treats an empty string as a falsy value.

Alternative way to divide a file into lines

Code Block
linenumberstrue
    import = function(content) {
      content.extract(re#(.+)#g)
        .tail()
    }

This technique lets the regular expression (applied "globally" (i.e. as many times as needed) to the content) do the work of splitting the file into lines. The String operator extract() will return all matches of "one character (or more) on a line" as an array of strings. We still discard the first (header) line, but no longer need to filter out empty lines.

Obtaining an input file

While it would be possible to make a query to the import function and pass it the entire exported file as a string, we found it preferable to have the function obtain the data file from a URL.

...