Function to work on strings on a list

I have a string list : A,B,C,D which I would like to use functions on. I'm having trouble understanding how to use the $ if I want to concatenate the string from the list with another string within the function. For example, below I am trying to go through the list and duplicate waves called A_test into A_test_1 and so on. The idea is that the function would run through the string, get the letter, append the appropriate suffix and make a wave out of the new name etc. These waves already exist so I don't have to make them.

The error I get now: "Can't use $ in this way in a function"

Function doit()

String list = "A;B;C;D"
String theWave
Variable index = 0


thewave  = StringFromList(index,list)

do
    Duplicate $thewave +"_test", $thewave +"_test_1"
    $thewave+"_test_1"[1,] = $thewave+"_test_1"[p-1]
    Display $thewave +"_test_1"
    index += 1
while (index <= 3)

End
   
One problem is that your change in thewave never happens inside the loop. Another is that you need wider use of parentheses () around terms. In particular,

$somewave + "_somestring" // this is wrong
$(somewave + "_somestring") // this is correct


Here is a different version.

Function DoList(strList)
    string strList
   
    string theSource, theNew
    variable index, np = ItemsInList(strList)
 
    for (index=0;index<np;index+=1)
        theSource = StringFromList(index,strList) + "_test"
        theNew = theSource + "_1"      
        Duplicate $theSource, $theNew
        wave swave = $theSource
        wave nwave = $theNew
        nwave[1,] = swave[p-1]
        Display swave
    endfor
    return 0
end



--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
The reason for the error message arises from the fact that Igor cannot handle a $-expression left of an "="-operator.
Duplicate $thewave +"_test", $thewave +"_test_1"
wave newwave=$thewave +"_test_1"
newwave[1,] =newwave[p-1]

should work, although the sense of the assignment with "[1,]" and "[p-1]" is unclear to me (copying the first value into the whole wave can be done easier).

@jjweimer
" $somewave + "_somestring" // this is wrong ": This is not really wrong ("$" has lower priority than "+"), but in general I agree that parentheses help if the order of execution is unclear.

And for curiosity:
Which Igor-Version is CountofItems from? My Igor 6 uses ItemsInList.
Why is the index increased twice?
HJDrescher wrote:
...
And for curiosity:
Which Igor-Version is CountofItems from? My Igor 6 uses ItemsInList.
Why is the index increased twice?


Yes. I will fix these two mistakes in my posting.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville