Multidimensional arrays¶
/marray -aTNBAV <name> [N..] <item> <value>
/marray -eTNBAV <name> [N..] <N> <item> <value>
/marray -iTNBAV <name> [N..] <N> <item> <value>
/marray -d <name> [N..] <N>
/marray -f <name>
Adds/removes/inserts/modifies items in a multi dimensional table/array.
Parameters
<name> - Name of the table to modify.
[N..] - Indicates the item should be added/inserted/deleted from sub table position N, subsequent N parameters travels further down.
<N> - The Nth item in a table or sub table to modify.
<item> - The item name.
<value> - The item value.
Switches
-a - Add a new item to a table.
-e - Edit a item in a table.
-i - Insert a new item to a table.
-d - Delete a item from a table.
-f - Free/delete a table.
-T - Indicates the type is text.
-N - Indicates the type is a number.
-B - Indicates the type is a boolean.
-A - Indicates the type is a sub table/array.
$marray(name, N, [N..])
Gets the Nth item in a table, subsequent N parameters gets the Nth item from a sub table, infinite sub depth.
Parameters
name - The outer table name.
N - The Nth item in the table.
[N..] - The Nth item in a sub table, subsequent N parameters travels further down.
Properties
.item - Gets the item name.
.value - Gets the item value.
.type - Get the item type. (0 = text, 1 = number, 2 = bool, 3 = sub table)
.json - Generate a json table from all items in the current table and all sub tables.
.ini - Generate a ini output from all items in the current table and all sub tables.
.xml - Generate a xml output from all items in the current table and all sub tables.
Example
; Add item1/value1 to the table 'table1'. //marray -a table1 item1 value1 ; Add sub table 'item2' to the table 'table1'. //marray -aA table1 item2 value2 ; Insert item3/value3 at position '1' in the table 'table1'. //marray -i table1 1 item3 value3 ; Print number of items in table 'table1'. //echo -ag Number of items in table1 is $marray(table1, 0) ; Print the first items in table 'table1'. //echo -ag First item in table1 is $marray(table1, 1).item ; Delete the first item in table 'table1'. //marray -d table1 1 ; Free the table 'table1'. //marray -f table1 ; Add a new sub table to table 'table1', //marray -aA table1 sub1 sub1 ; Add a new item to the sub table located at position '1' in table 'table1'. //marray -a table1 1 item1 value1 ; Print the first item in the table 'table1', which is a sub table. //echo -ag First item in table1 is $marray(table1, 1).item - $marray(table1, 1).type ; Print the first item in the sub table located at position '1' in table 'table1'. //echo -ag First item in sub table1 is $marray(table1, 1, 1).item ; Generates a json output of table 'table1'. // echo -ag $marray(table1).json ; Generates a ini output of table 'table1'. // echo -ag $marray(table1).ini ; Generates a xml output of sub table at position '1' in table 'table1'. // echo -ag $marray(table1, 1).xml
Updated by Per Amundsen almost 2 years ago ยท 73 revisions