I can not take a sub index of an array
Ex:
I have the following information:
Interface Tipo
“pppoe-ADSL1” “ADSL”
“pppoe-ADSL2” “ADSL”
“pppoe-ADSL3” “ADSL”
“pppoe-ADSL4” “ADSL”
“ether1” “Eth”
“ether4” “Eth”
declare an array and I loaded them in the variable “NomInt” with the interface and “TipoInt” the kind of the same, I try to do with pick but only succeeded in taking the full index, but not the sub index
Ex: Script
:global Array {{“pppoe-ADSL1”;“ADSL”};{“pppoe-ADSL2”;“ADSL”};{“pppoe-ADSL3”;“ADSL”};{“pppoe-ADSL4”;“ADSL”};{“ether1”;“Eth”};{“ether4”;“Eth”}};
:global TempArray;
:global NomInt;
:global TipoInt;
:set TempArray [:pick $Array 3];
:set NomInt [:pick $TempArray 0];
:set TipoInt [:pick $TempArray 1];
Running this script I get the following
[admin@MikroTik] > :environment print
“Array”={{“pppoe-ADSL1”; “ADSL”}; {“pppoe-ADSL2”; “ADSL”}; {“pppoe-ADSL3”; “ADSL”}; {“pppoe-ADSL4”; “ADSL”}; {“ether1”; “Eth”}; {“ether4”; “Eth”}}
“TempArray”={{“pppoe-ADSL4”; “ADSL”}}
“NomInt”={{“pppoe-ADSL4”; “ADSL”}}
“TipoInt”=
I wish that it reads as
“NomInt”={“pppoe-ADSL4”}
“TipoInt”={“ADSL”}
I’m using the Version 4.3
In what I believe, in the declaration of array index to obtain …? I’m not tired of testing. if there is no direct way I have to do with “find” but I do not like doing this.
From already thank you very much
PD. Sorry for my English
I found a way to get what I want.
strange but it works
Ex:
:global Array {{“pppoe-ADSL1”;“ADSL”};{“pppoe-ADSL2”;“ADSL”};{“pppoe-ADSL3”;“ADSL”};{“pppoe-ADSL4”;“ADSL”};{“ether1”;“Eth”};{“ether4”;“Eth”}};
:global TempArray;
:global NomInt;
:global TipoInt;
:set TempArray [:pick $Array 3];
:set TempArray [:tostr $TempArray ];
:set TempArray [:toarray $TempArray ];
:set TempArray [:tostr $TempArray ];
:set TempArray [:toarray $TempArray ];
:set NomInt [:pick $TempArray 0];
:set TipoInt [:pick $TempArray 1]
and this gives me what I want
[admin@MikroTik] > :environment print
“Array”={{“pppoe-ADSL1”; “ADSL”}; {“pppoe-ADSL2”; “ADSL”}; {“pppoe-ADSL3”; “ADSL”}; {“pppoe-ADSL4”; “ADSL”}; {“ether1”; “Eth”}; {“ether4”; “Eth”}}
“TempArray”={“pppoe-ADSL4”; “ADSL”}
“NomInt”={“pppoe-ADSL4”}
“TipoInt”={“ADSL”}
Will it be a Bug in array handling OS?
But I think it should be:
:global Array {{“pppoe-ADSL1”;“ADSL”};{“pppoe-ADSL2”;“ADSL”};{“pppoe-ADSL3”;“ADSL”};{“pppoe-ADSL4”;“ADSL”};{“ether1”;“Eth”};{“ether4”;“Eth”}};
:global TempArray;
:global NomInt;
:global TipoInt;
:set TempArray [:pick $Array 3];
:set NomInt [:pick $TempArray 0];
:set TipoInt [:pick $TempArray 1]
But with this script I have this, (and not what I want):
“Array”={{“pppoe-ADSL1”; “ADSL”}; {“pppoe-ADSL2”; “ADSL”}; {“pppoe-ADSL3”; “ADSL”}; {“pppoe-ADSL4”; “ADSL”}; {“ether1”; “Eth”}; {“ether4”; “Eth”}}
“TempArray”={{“pppoe-ADSL4”; “ADSL”}}
“NomInt”={{“pppoe-ADSL4”; “ADSL”}}
“TipoInt”=
Well, I hope that will work for someone 