get info using "print as-value"

Hello ,
I’m trying to get some info from my modem
I want to get “current-operator”

this is what I did

:global modem [/interface lte info lte1 as-value ];
:global OP ([:pick $modem 0]-> "current-operator");

but I get nothing …

Why?

how can I save the current-operator of the sim ?

Thanks ,

It seems the info command returns info about the particular item, so rather than picking 0 out of the result, you should just get the property, i.e.

:global OP ($modem->"current-operator");

In fact, if this is the only value you want to store, you can save yourself a step:

:global OP (([/interface lte info lte1 as-value])-> "current-operator");

or even better

:global OP [/interface lte get lte1 current-operator];

this command doesn’t work

:global OP [/interface lte get lte1 current-operator];



input does not match any value of value-name

you are missing the info .

but never mind i want to extract from the info several more values

but can you explain to me how the command works?
I mean , what does “->” do ?

Thanks ,
I know how to use it , but I want to understand it

Thanks ,

It’s an associative array access operator.

Arrays can have not just indexes, but “keys” also. f.e.

{a=1;b=2;3;4}

is an array where the first member has the key “a” and the value “1”, a second member with key “b” and value “2”, a third member with no key and a value of “3”, and a forth member with no key and a value of “4”.

When you use :pick, you get the value of an item at a particular index (regardless of its key), with 0 being the first member, 1 being the second and so on, so

:put [:pick ({a=1;b=2;3;4}) 1]

outputs “2”.

With the “->” operator, you can instead target an item by its key, so

:put (({a=1;b=2;3;4})->"b")

outputs “2”, and it will still output “2”, regardless of where “b” is in the array, e.g.

:put (({a=1;3;4;b=2})->"b")
:put (({b=2;a=1;3;4})->"b")

all return “2”, while

:put [:pick ({a=1;3;4;b=2}) 1]

would output “3”, and

:put [:pick ({b=2;a=1;3;4}) 1]

would output “1”.

When you use “info as-value”, an associative array is returned, where the property name is the key, and the property’s value is the array value. You could use :pick to get a particular item, but as RouterOS versions change, the property may be moved around. Using “->” allows you to keep referring to the same item, as long as the property name stays the same.


If you’re asking about its syntax and why it’s the way it is… Long story short, bad language design on top of bad language design. All the brackets are used to make it clear to the parser which is which and which is where in the order of things, because the parser is not smart enough to figure it out otherwise. The quotes on the right side of “->” are supposed to be optional when there’s no space or dash in the property name, but certainly in older versions (I’m not sure about newer ones), there were bugs when you omit them.

Thanks!,