I need some assistance on how I can reference arrays using a variable:
:local ifs {"ether1"; "ether2";};
:local ether1 {1.1.0.0/16; 2.2.0.0/16;};
:local ether2 {192.168.1.0/24; 192.168.2.0/24;};
:local num 1;
:put ($ether1->$num);
:foreach if in=$ifs do={
:put ($if->$num);
}
Output:
2.2.0.0/16
Expected output:
2.2.0.0/16
2.2.0.0/16
192.168.2.0/24
A) ROS not supports dynamic names for variable
B) but you can use script from script trick as here - http://forum.mikrotik.com/t/name-var-dynamic/111914/4
Thanks, I assumed as much and worked around this limitation by using nested arrays (similar to a hash table). For those that are interested herewith a post with a functional script:
http://forum.mikrotik.com/t/automating-address-list-maintenance-manrs-compliance/115375/1
Herewith sample array definition:
:local ifs {
{"filter-external"; 1; 1; {}; {}};
{"filter-external-src"; 1; 0; {}; {}};
{"filter-peer1-vlan645"; 1; 1; {205.37.17.206}; {}};
{"filter-peer2-vlan417"; 1; 1; {205.19.28.105}; {}};
{"filter-ixp1"; 1; 1; {205.60.8.156; 10.20.200.0/22}; {}};
{"filter-upstream1-vlan143"; 1; 1; {205.22.33.34}; {}};
{"filter-upstream2-vlan480"; 1; 1; {205.25.155.42}; {}};
{"filter-upstream3-vlan85"; 1; 1; {205.79.22.66}; {}};
{"filter-upstream4-vlan782"; 1; 1; {205.242.227.65}; {}};
};
Then when working with the information in the array:
:foreach if in=$ifs do={
:local name ($if->0);
:local prefixes ($if->3); # load manual prefixes array as '$prefixes'
# ie. when name = 'filter-ixp1' then '$prefixes->1' = 10.20.200.0/22
...
}