Problem with ip pool ranges in script but not in CLI

I have a script is to build an OpenVPN compatible address pool. It does so by going through the possible combinations and build up a “Ranges” variable containing a comma separated liost of all valid /30 ranges.

The /ip pool add fails with: value of range must have ip address after ‘-’

The ewrror does also happen if I do the for loop only for 2 entries (0 to 1), but works for one single entry (no comma). The strange thins is that I :put the Ranges variable to the console and enter the “/ip pool add” manually copy/pastiong the range string (assembling it to a single line first) the add works, Also if I copy/paste the ranges to teh script by preceding the :put Ranges by a :set Ranges “10.9.9.1-10.9.9.2,10.9.9.5-10.9.9.6,10.9.9.9-10.9.9.10,…” the script will work. The put typeof copnfirms that Ranges is of str type each time.

Script:

:local PoolName "ovpn-pool";
:local OpenVPNNetwork "10.9.9";
:local Ranges "";

:for i from=0 to=63 do={
  :if ( $i = 0 ) do={ 
    :set Ranges { "$OpenVPNNetwork." . ( 1 + $i * 4 ) . "-" . $OpenVPNNetwork . "." . ( 1 + $i * 4 + 1 ) };
  } else={
    :set Ranges { "$Ranges," . $OpenVPNNetwork . "." . ( 1 + $i * 4 ) . "-" . $OpenVPNNetwork . "." . ( 1 + $i * 4 + 1 ) };
  };
};

:put $Ranges;
:put [ :typeof Ranges ]

/ip pool add name=$PoolName ranges=$Ranges