Yeah there are two types of arrays, one is a dictionary/map and other is list. When accessing members, dicts/maps use ->“name”, while list use NO quotes ->3.
And “print as-values” uses an array that be described as a “list-of-dictionaries” — why you need to two arrow operators:
[print as-value]->0->“attributes-name”
One tip is use serialize to see what the array looks like, and then using the right ->#->“name” becomes a little easier to see:
Basically anything in JSON that uses a needs to use -># format. If you see a {} then its a map/dictionary so you need the ->“name” style.
2nd tip be you can get a CSV using from any “print as-value” — there you need the options=dsv.remap which is needed for the $array->#->“name” structure:
The important part is this changes the order used to access the array from list-of-dictionary to a dictionary-of-lists:
$array->“name”->0
from the results of “print as-value” — so you could get a simple list of the ANY attribute. So it was “name” field:
([:deserialize from=dsv … [:serialize to=dsv […/print as-value] … ]]->“name”)
It is called a 2D array and there are more array lines after the first line. This because more than one file exits in /file
> :local test {{name="cccc"; name1="ddddd"};{name="eeeee"; name1="fffff"}}; put $test; put {$test->"name1"}
name=cccc;name1=ddddd;name=eeeee;name1=fffff
> :local test {{name="cccc"; name1="ddddd"};{name="eeeee"; name1="fffff"}}; put $test; put {$test->0->"name1"}
name=cccc;name1=ddddd;name=eeeee;name1=fffff
ddddd
> :local test {{name="cccc"; name1="ddddd"};{name="eeeee"; name1="fffff"}}; put $test; put {$test->1->"name1"}
name=cccc;name1=ddddd;name=eeeee;name1=fffff
fffff
@ammo there are indeed two different array types but that is not changing the basic working here.
I had feature request for :serialize to=csv… and in the case MikroTik called the “print as-value” array (which lead to dsv.remap) as a “list-of-dictionaries”. Everyone has their own preferred terms it seems.
I was referring the accessors do vary on based on the array “sub-type”.
Not at all, in fact you teach badly and they learn worse.
It is wrong, you should never use numbers or IDs in the script.
I understand that was just an example, but wrong examples are still wrong.
Because, for example, in the terminal there is no point in doing all this to get the IP, then, if it works visually, it is thought that it is the correct way to do the scripts.