[pmwiki-users] summing variables

Peter & Melodye Bowers pbowers at pobox.com
Tue Apr 22 16:00:25 CDT 2008


> I have variables like this (:var1:2,5:) (:var2:3,4:)
> (:var3:23,78:) ...
> (:var35:0,45:). I'd like to know is there an easy way to sum all 35
> variables together? So that I don't need to use for example 
> {(add {$:var1}
> an then all those 35 variables.

WikiSh has this capability using a syntax like {$:var${counter}} to work
with "pseudo-arrays".  If you think you would be interested in this I can
code it up for you and put it out on the WikiShExamples page.

It would look *something* like this:

===(snip)===
Set i = 1
Set --pv total = 0
While test ${i} -le 35
Do
   set --pv total += {$:var${counter}}
Done
===(snip)===

That would be placed in a page somewhere (Mygroup.Totalcode, for instance)
and then run from your page via {earlymx(wikish source Mygroup.Totalcode)}.
Then you could access the variable as {$total} elsewhere within your page.  

No guarantees on this - I haven't actually run it and so I might have typos
causing syntax problems or something.  

This is a case where WikiSh works just fine entirely in "read-only" mode
which is the default.

-Peter




More information about the pmwiki-users mailing list