AnsweredAssumed Answered

How to process an arbitrarily-sized list of items

Question asked by Michael_Lowry on Nov 21, 2013
Latest reply on Jul 7, 2015 by MikeBurnham603785

I would like to do something similar to the this for loop in bash:

 

#!/bin/bash
string_list="abc 123 xyz 789"
 for string in $string_list; do     echo $string done

I tried to do it by creating create a string array and then acting on the elements of the array, but I ran into a problem: there seems to be no way to create a string array of arbitrary size — in other words, an array whose size is specified in a variable. The documentation suggests that it should work, but it does not.

!  Split a comma-delimited string fill a new string array.
:SET &LIST# = "abc,123,xyz,789"
:SET &COUNT# = 4
:DEFINE &COUNT#, unsigned
:DEFINE &STRING_ARRAY#, string, &COUNT#
:FILL &STRING_ARRAY#[] = STR_SPLIT("&LIST#", ",")
:SET &INDEX# = 1
:WHILE &INDEX# <= &COUNT#
! Do something, such as:
:  SET &STRING# = &STRING_ARRAY#[&INDEX#]
:  PRINT "String number &COUNT#: &STRING#"
:ENDWHILE
The Automation Engine demands that the Array size argument of the :DEFINE statement be an integer. If you try to put a variable in there, as above, it won’t even let you save the job. Obviously in this example, I could just use the number 4. However, I want to be able to handle a general case where the number of elements is not known ahead of time. Yes, know I could stick the items in a new temporary VARA and use PREP_PROCESS_VARA* to act on each item in the VARA — but creating an external object seems like overkill.

I feel certain that this must be (or ought to be) a straightforward way to use UC4 scripting commands to go through an arbitrarily-sized list of items and act upon each the members. What’s the best way to do something like this?

* Also, it would be nice if there were a PREP_PROCESS_ARRAY statement that would create a data sequence reference to an array, but this still depends on being able to create an arbitrarily-sized array in the first place.

Thanks in advance.

Outcomes