What I've never been able to do with the syntax here is exit out of the "print follow-only"...
Why did not you ask the Cat?
Is that going to be the title of your book on RouterOS scripting?
It is these /containers that always give me troubles in scripting, since commands trigger events (i.e. "/container start" == request a start) - but there are no on-status-change= handlers built-in. And the "print follow-only" is pretty useful when messing with these – so more an example of slight more
practical usage of they scripting tricks here. Some :while/:retry approach for /container works. But I could never figure out to
simple way to exit if using "print follow-only where" described here... without more code and/or jobs/:execute.
Perhaps a more simple example help others here...
Example: Using "find" as an iterator, instead of :foreach
A more basic example of using this technique is getting a list of /ip/address. Here the "[find] as iterator" is way shorter than the alternative expressions:
/ip/address find [:put $address]
172.16.174.254/24
172.16.174.1/32
192.168.216.1/24
192.168.101.173/24
172.28.8.61/24
10.88.100.113/24
Printing same with a :foreach, it's much longer:
/ip/address { :foreach i in=[find] do={ :put [get $i address] }
# or same using "fully-qualified" commands
:foreach i in=[/ip/address/find] do={ :put [/ip/address/get $i address] }
172.16.174.254/24
172.16.174.1/32
192.168.216.1/24
192.168.101.173/24
172.28.8.61/24
10.88.100.113/24
And the normal "print" includes the headers which are unavoidable:
/ip/address/print proplist=address
Flags: X - DISABLED, D - DYNAMIC
Columns: ADDRESS
# ADDRESS
0 172.16.174.254/24
1 172.16.174.1/32
...
While "print as-value", using a :foreach is possible... you need to deference the array provided by "print as-value", so also longer:
:foreach i in=[/ip/address/print as-value] do={:put ($i->"address")}
172.16.174.254/24
172.16.174.1/32
...
On the which one is "faster", I don't know. With 100 IPs, all were in the 8-12ms range, and all varied within that. But you can use the :time function to check (which is how I got those numbers):
:put [:time {/ip/address find [:put $address]}]
172.16.174.254/24
172.16.174.1/32
...
00:00:00.005610
All do the same things, pick you poison. But the "find" technique is useful one... And while I use :put, it could be your own function too (by passing the find variables to the function).