Array modification

I try to create a script that get information from the configuration of the router or from some commands and store the result in an array.

I have declare some pppoe-client links and want to know the status of each one and save it in different array, one per pppoe-client link.

:global LD1 {user="" ; interface="ether1"; operstatus="" ; admstatus=""; upcounter=0}
:global LM1 {user="" ; interface="ether1"; operstatus="" ; admstatus=""; upcounter=0}
:global LDV1 {user="" ; interface="ether1"; operstatus="" ; admstatus=""; upcounter=0}
:global LV2 {user="" ; interface="ether1"; operstatus="" ; admstatus=""; upcounter=0}
:global LM2 {user="" ; interface="ether1"; operstatus="" ; admstatus=""; upcounter=0}
:global LDV2 {user="" ; interface="ether1"; operstatus="" ; admstatus=""; upcounter=0}

:global LOGIN {"LD1"; "LM1"; "LDV1"; "LV2"; "LM2"; "LDV2"}

I have create a loop to parse every pppoe-cleint link :

:foreach i in $LOGIN do={:interface pppoe-client monitor $i once do={:set ($i->"operstatus") $status}}

But the result is not what i want :

 environment print 
LD1={admstatus=""; interface="ether1"; operstatus=""; upcounter=1; user=""}
LDV1={admstatus=""; interface="ether1"; operstatus=""; upcounter=0; user=""}
LDV2={admstatus=""; interface="ether1"; operstatus=""; upcounter=0; user=""}
LM1={admstatus=""; interface="ether1"; operstatus=""; upcounter=0; user=""}
LM2={admstatus=""; interface="ether1"; operstatus=""; upcounter=0; user=""}
LOGIN={"LD1"; "LM1"; "LDV1"; "LV2"; "LM2"; "LDV2"}
LV2={admstatus=""; interface="ether1"; operstatus=""; upcounter=0; user=""}

what is wrong ?

Impossible to know when it is not clear what would be the expected result…
However, I feel with you. Debugging RouterOS scripting is extremely tricky and it often behaves different from what you expect.
What I learned the hard way is to always break up things in small statements. The expression evaluator is very primitive.
However, I don’t know how to apply that to your problem.

the result as to be for exemple :

LD1={admstatus=""; interface="ether1"; operstatus="connected"; upcounter=1; user=""}

why?
the result is set to $status. is $status set to “connected” outside of your example?

no $status is not fixed, it’s read from the command :

:interface pppoe-client monitor $i once

it can be connected or disconnected or something else

But where is that transferred to $status? I don’t see that anywhere.
I think you need to:
:set $status [:interface pppoe…]
and then you can set the array variable to $status.

it’s done with this line

:foreach i in $LOGIN do={:interface pppoe-client monitor $i once do={:set ($i->“operstatus”) $status}}

when you do :interface pppoe-client monitor LD1 once do={:set (LD1->“operstatus”) $status

the actual status is put in the array LD1, at operstatus variable value.

I want this for each one of my value in array LOGIN

As I wrote earlier, the expression evaluator is very primitive.
Separate what you want to do in some steps.
First put the status in a variable, then put the variable value in the array.
But I don’t understand this “monitor” command and the relation to the $status variable, so I could be wrong.