Global variables whose names are formed in a for each loop

Hi,

Im in a real muddle, and I hope someone can help me.

I have three simple queues, and I want to ready the value of total-bytes into three global variables, and then use the value of these global variables in subsequent calculations. I can set the variables, but cant see how to access the values of them.

The three queues are named a, b, and c

I have a script to set up the global variables which are, say
a-old
b-old
c-old

I have a foreach loop

:foreach i in [/queue simple find] do ={
:set ([/queue simple get $i name] . “-old”) [/queue simple get $i total-bytes]
}

This works OK, and if I do a env pr at a terminal window after each time I run the script, I can see the changes to the total-bytes of each queue as traffic flows through the router.

But when I try to log the values, eg put in the loop

:log info $([/queue simple get $i name] . “-old”)

The script will not run. If I leave out the dollar sign, the name of the variable appears in the log, not its value.

Any ideas would be very gratefully received. I’ve been puzzling over this all day !!

rgds
Jim Heck

I don’t know if you can generate variable names with an expression … maybe.

Unfortunately the syntax/script interpreter seems to be pretty much one- or two-pass
The closest i have come to accomplishing this feature is to generating a / system script and then executing it.
An “eval” type instruction would have been very useful for these cases.
Perhaps you could use “arrays” (lists)?

:local s ( [ :toarray $c1 ] . $c2 . $c3 )
:put [ :pick $s 1 ]