put members of /interface member list into variable array [SOLVED]

howdy skillfully mt people,

problem:
Parse out → /interface list member of list “IL_wanif” into array variable will result with empty variable.

IL_wanif members → wlan0 and inactive lte1-4 ( let say lte1,lte2,lte3,lte4)

:local ilm {:toarray [/interface list member print as-value where list=IL_wanif]};put $ilm

result with:

.id=*55;comment=;interface=eth0_wlan0;list=IL_wanif;.id=*5d;comment=;interface=eth0_lte3;list=IL_wanif;.id=*61;comment=;interface=eth0_lte10;list=IL_wanif;.id=
*62;comment=;interface=eth0_lte0;list=IL_wanif;.id=*65;comment=;interface=eth0_lte2;list=IL_wanif;.id=*66;comment=;interface=eth0_lte1;list=IL_wanif

looks almost correct. then little more specific with ($ilm ->“interface”)


:local ilm {:toarray [/interface list member print as-value where list=IL_wanif]->"interface"};put $ilm
or
:global ilm {:toarray [/interface list member print as-value where list=IL_wanif]};put ($ilm->"interface");

result:

expected result list of interfaces array

this will populate and giving result list of interfaces

:foreach interface in=[/interface list member print as-value where list=IL_wanif] do={:put ($interface->"interface")}

result:

eth0_wlan0
eth0_lte3
eth0_lte10
eth0_lte0
eth0_lte2
eth0_lte1

this command will fail to store result into array:

:foreach interface in=[/interface list member print as-value where list=IL_wanif] do={:global ilm [:toarray ($interface->"interface")]}

it only store 1 to variable the last interface let say “eth0_lte1”

any help would be appreciated..


regards,

It’s all full of errors, obviously it doesn’t work.

Where did you read this 5h1t?
[…]:local ilm {:toarray [/int[…]


if you overwrite the variable every time (recreating it) it is obvious that it always contains only the last entry.
You really lack the ABC of programming, regardless of whether it is RouterOS or anything else…
[…] _wanif] do={:global ilm [:toarray ($int […]



{
:local iflist [:toarray ""]
/interface list member
:foreach ifc in=[find where list="IL_wanif"] do={:set iflist ($iflist , [get $ifc interface])}
:put [:typeof $iflist]
:put $iflist
:put ($iflist->0)
:put ($iflist->1)
}

yes still newbie scriptor..trial by errors…
wrong logic yes…
let me learn your working code after im back from hospital ..

regards

:confused: I hope nothing serious…

yea hopefully everything just fine :slight_smile:

anyway it works ! thank you.
rextended code for gathering interfaces into array
this could be hint to newbies seeking for answer :slight_smile:

:global iflist [:toarray ""]
/interface list member
:foreach ifc in=[find where list="IL_wanif"] 	do={:set iflist ($iflist , [get $ifc interface])}

than trying to parse interfaces into array using syntax "print as-value where list="

regards,