
rmh_va
Novice
Aug 16, 2011, 8:27 PM
Post #3 of 17
(928 views)
|
|
Re: [FishMonger] perl variable name interpolation in a loop;
[In reply to]
|
Can't Post
|
|
i can't get the interpolation to work in a loop... In my example, I have 8 variables with the names $sub1, $sub2, etc... I tried to assign a temp vatiable to the interpolated result of the assign statement, utilizing the value of the loop... the idea is to not have to hard code the variable names... so I constructed a loop... while ($i < 9) { $temp = ("$sub"."$i"); @x = split(/\//, $temp); # data has embedded / between 3 fields; print 'element 1 = ',$x[0],''; print 'element 2 = ',$x[1],''; print 'element 3 = ',$x[2],''; } I can't get the $temp variable to initialize... I have printed the array being returned by DBI, there is data in it... It's not the split, not the data.. it's the interpolation... I tried printing $temp, it prints the value of the loop (1, 2, 3, etc.)... there is something I'm not getting right in trying to interpolate the variable name in the loop... Please, I don't need help with the split, the print, or anything else, only how to interpolate the variable name using the value of the loop...
|