PERL creating variable names with other variable values.
by "Peter Newton" <c-newton(at)ihug.co.nz>
|
| Date: |
Sun, 11 Feb 2001 22:24:35 +1300 |
| To: |
<hwg-techniques(at)hwg.org> |
| |
todo: View
Thread,
Original
|
|
Hello All,
Thanks for everyones responses private and on the list.
I like to end the thread with a solution incase anyone searches the
archives.
So here it is:-
${dec."$day"} = blah blah ;
the curly braces tell perl where the variable NAME starts and ends, adding
the dot and the double quote marks adds the VALUE of $day to the $dec NAME.
So if $day = 12;
then
${dec."$day"} == $dec12;
I'm also looking at arrays and hashes as an alternative.
Many Thanks
Peter Newton
I hope I can make this question clear, I'm trying to create (using PERL) a
number of variables using a loop and a count so that I can use the count
value to append to the variable name like so:
for ($day=1; $day <= 31; ++$day) {
$dec1 = ........ blah blah;
}
But I want the variable $dec1 to go to $dec2 etc each time round the loop.
using $day to append the appropriate digit to the variable name $dec.
I've tried:-
$dec$day
"$dec"."$day"
etc etc
I'm sure I've done this before but cannot find anything.
Can anyone help??
many thanks
Peter Newton
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA