Hi All-
I am trying to get a simple recursive script running and am having some problems. Thanks in advance for any answers.
code:
/system script add name=tr source={
:local plsrecurs
:global recursiveprint (“:global recursiveprint;
:local runFunc;
:put ("start after local: ".$start)
:if ($start < 11) do={
:set start ($start+1)
:put $start
:set runFunc ($start . "; " . $recursiveprint)}
:set runFunc [:parse $recursiveprint]
:put $runFunc
}else={:put "done":}
;”)
:set plsrecurs (":local start 1; " . $recursiveprint)
:set plsrecurs [:parse $plsrecurs]
:put $plsrecurs
}
The parser seems to think everything is OK.
/system script run tr
output:
start after local: 1
2
syntax error (line 3 column 32) → I can’t figure out the syntax error here.
Is there a way to debug this? It looks like a complaint over :global recursiveprint (":global recursiveprint;
^
Another question:
If I wanted to have variable start be a local variable in the function instead of passing in the argument, how do I do that? As it is, it can’t go inside the recursive function because it will loop. It doesn’t seem to work if one adds it after :local runFunc either.
I have taken a look at the example in the documentation and I have it working. I must be missing something simple. Any help is greatly appreciated… Thanks in advance.
I suppose I should add that I tried this as well but no go:
/system script add name=tr source={
:local plsrecurs
:global recursiveprint (“:global recursiveprint;
:local runFunc;
:put ("start after local: ".$start)
:if ($start < 11) do={
:set start ($start+1)
:put $start
:set runFunc (":local start " . $start . "; " . $recursiveprint)
:set runFunc [:parse $recursiveprint]
:put $runFunc
}else={:put "done":}
;”)
:set plsrecurs (":local start 1; " . $recursiveprint)
:set plsrecurs [:parse $plsrecurs]
:put $plsrecurs
}
/system script run tr
expected end of command (line 10 column 6)
I am replying to my own post… Maybe this will help someone else. Maybe some clarification for myself would be good.
- I don’t understand why I am passing in a quoted 1, “1”, when I am working on an integer. Are strings and integers looked at the same or is this a special case due to it’s recursive nature?
IE. This, ":local start \"" . $start . "\"; " is read as ':local start "1"; ’ by the parser. Ignore the ticks
- I looked at the code too long yesterday:
this:
:set runFunc (":local start " . $start . "; " . $recursiveprint)
:set runFunc [:parse $recursiveprint]
^wrong
should have been:
:set runFunc (":local start \"" . $start . "\"; " . $recursiveprint)
:set runFunc [:parse $runFunc]
^right
Here is the final working code:
/system script add name=tr source={
:local plsrecurs
:global recursiveprint (“:global recursiveprint;
:local runFunc;
:put ("start after local: ".$start)
:if ($start < "11") do={
:set start ($start+1)
:put $start
:set runFunc (":local start \"" . $start . "\"; " . $recursiveprint)
:set runFunc [:parse $runFunc]
:put $runFunc
} else={:put "Done"}
;”)
:set plsrecurs (":local start "1"; " . $recursiveprint)
:set plsrecurs [:parse $plsrecurs]
:put $plsrecurs
}