Read array from a file

readarray name

Reads in and returns an array from a file with the specified name. Each line in the file becomes an item in the array. Empty lines are omitted. If a line consists of multiple words (separated with white spaces then) a subarray of words is created and added as an item to the array. If at least one item in the array is a subarray then all other items which are not yet arrays are converted to single-item arrays.

If the name does not contain an absolute path then the file is assumed to be in the current directory, specified with the :pool_cfg,"current_dir variable.

The name can be also a http adress.

Example:

"k := {abc 123 x y z}
writedata :k "array1.txt

"m := readarray "array1.txt
print :m

"l := [123 abc [a [b c]] {x y z}]
writedata :l "array2.txt

"n := readarray "array2.txt
print :n

Output:

{abc 123 x y z}
{{123} {abc} {a [b c]} {x y z}}

See also:

Array

Table of Content