rwarray extension adds two functions,
reada(), as follows:
ret = writea(file, array)
writea()understands multidimensional arrays. It returns one on success, or zero upon failure.
ret = reada(file, array)
reada()is the inverse of
writea(); it reads the file named as its first argument, filling in the array named as the second argument. It clears the array first. Here too, the return value is one on success and zero upon failure.
The array created by
reada() is identical to that written by
writea() in the sense that the contents are the same. However,
due to implementation issues, the array traversal order of the recreated
array is likely to be different from that of the original array. As array
traversal order in awk is by default undefined, this is (technically)
not a problem. If you need to guarantee a particular traversal
order, use the array sorting features in gawk to do so
(see Array Sorting).
The file contains binary data. All integral values are written in network byte order. However, double precision floating-point values are written as native binary data. Thus, arrays containing only string data can theoretically be dumped on systems with one byte order and restored on systems with a different one, but this has not been tried.
Here is an example:
@load "rwarray" ... ret = writea("arraydump.bin", array) ... ret = reada("arraydump.bin", array)