Hallo,
how to set an element in this array? See example.
[admin@Mikrotik] >:global x aa,bb,cc,dd,ee,ff
[admin@Mikrotik] > :put [:pick $x 2]
cc
With pick command I can read element 2. How to set element 2 in array to an other value? For example how is the command to set element 2 to ccc?
So that the command :put [:pick $x 2] has the result ccc?
Thanks in advance!
Does anybody know it?
I’ll be satisfied to know if it is possible or not.
mrz
3
As far as I know you can’t do it directly.
However you can use something like example above:
:global aaa 1,2,3,4,5
# replace third value with 9
:set aaa ([:pick $aaa 0 2] , "9" , [:pick $aaa 3 5])
:environment print
Output:
“aaa”={“1”; “2”; “9”; “4”; “5”}
Yes, you can, but you need to assign “names” to each value in the array:
:global x {"1"="a";"2"="b";"3"="c";"4"="d"}
:put $x
Output: 1=a;2=b;3=c;4=d
:set ($x->"3") "ccc"
:put $x
Output: 1=a;2=b;3=ccc;4=d
Hope it helps.
Not necessarily. If you know which index you want to edit you can go like this:
set ($arrayVariable->$arrayIndex) $newValue
Where $arrayIndex is an integer.
You are right, haven’t tried that approach!