0

I have a an old csh script (which hopefully I have time to rewrite in perl) which has a series of variables wmr1, wmr2 ... wmr24. What I would like to do is echo the values of each variable using a foreach loop eg

foreach i(`seq 1 24`)
   echo ${wmr$i}
end

Can this be done in csh or using a perl one liner (using a symbolic refernce?)? I am not sure how to combine the integer $i with wmr and output the value of $wmr1 $wmr2 etc. echo ${wmr$i} in the loop gives me the error Missing }.

moadeep
  • 3,988
  • 10
  • 45
  • 72
  • Surely, it can be done. Show us what did you try? Is this a coding service? – devnull May 29 '13 at 10:57
  • @devnull I have tried echo ${wmr$i} and various other combinations. There isn't much out there in terms of csh help and I wasn't sure how best to scour the web for help in this task – moadeep May 29 '13 at 11:01

1 Answers1

2

You can try this

 foreach i (`seq 1 24`)
     eval 'echo $wm'$i
 end

The eval statement will evaluate the string given to it. So replace echo with any other command you may want to use.

dwalter
  • 7,258
  • 1
  • 32
  • 34