The intention is to initialize the global variable “gArr” in the script only if it does not already exist.
This part works ok, but the latter “:put $gArr” does not output it, ie. the output is empty.
I suspect an internal parser error regarding scope visibility…
First you are trying to use undeclared variable gArr
Then you are declaring global variable with the same name in ‘if’ scope.
I assume that you want to access already existing global variable and if it does not exist or is empty then add first entry, in that case script should look something like this:
{
# declare variable that you are trying to access
:global gArr;
:if ([:typeof $gArr] = "nothing" or [:tobool [:len $gArr]] = false) do={
# make changes to gArr
:set $gArr { key1="val1"}
}
:put $gArr
}