Good evening. I have a list named languageCharactersList. I begin my
iteration through elements in that list with this:

languageCharactersList.eachWithIndex( it, i ->

I hope to make this more generic, so that I can build a variable name that
points to the appropriate list, which then allows me to keep my iteration
loop generic.

I'd like to do this:
def languages = ['english', 'french', 'spanish']
def englishCharsList = [....]
def frenchCharsList = [.....]
def spanishCharsList = [....]

I'll set up an iterator to grab each of the languages. Within that
iterative loop I will set a general variable like so:
def CharsList = "english"+"CharsList" (then "french", then "spanish",.....)

I was hoping I could then set up the generic iterator like so:
*"$CharsList"*.eachWithIndex{ it, i ->
or like so
*$CharsList*.eachWithIndex{ it, i ->

But Groovy doesn't allow this approach, and throws a stack trace.

How can we employ a variable assignment in that list iterator statement
so it can be generalized?

Thanks in advance.
Jim

Reply via email to