Skip to content

read_table

Syntax

read_table(table_name, "filename", key_col, val_col)

Parameters

table_name
The table to update
filename
The name of comma-separated file, surrounded by quotes. The file-name may include the path to the file.
key_col
The index of the column containing keys
val_col

The index of the column containing values

Description

Updates a provided table with a series of key-value pairs from the specified filename.

The file must be a comma-separated-value file that contains the indicated columns. The assignments of key-value pairs is sequential, so that if a key occurs more than once in the file, the final value will be associated with that key in the table.

Empty lines in the file are ignored.

Lines with a non-numeric value in the first column are ignored.

The value associated with any key that appears in the key_col is replaced by the value in the file. Other keys are not affected.

Note

This action does not change any key-value pair in the table if the key does not occur in the file. This means that this action can only increase the number of key-value pairs in the table.

An error occurs if the file is not found, or if the column indices do not exist.

Examples

population.csv

key,     value
"[1,2,3]", 5
"[4,5,6]", 10
"[7,8,9]", 15
5, 5
10, 10
15, 15

variables {
    shared table my_shared_table
    my_shared_table.default_value = 999
}

condition LOADING {
    meta_start_state = Start

    state Start {
        # populate table with key and value from .csv file
        read_table(my_shared_table, "population.csv", 0, 1)

        wait()
        default()
    }
}

See Also