--- Tyler Cruickshank <[EMAIL PROTECTED]> wrote: > My keys are simply data.hr1, data.hr2, data.hr3, where each key is incremented via >the for loop. > The problem seems to be that when I use $specSum{$name}[$i] where $name would be >data.hr1, > data.hr2, data.hr3 ... it doesnt work. How can I use a variable as a key to a hash? > My code > works just fine when I write $specSum{'data.hr1'}[$i]. A snippet of my code is >pasted below. > Thanks for the help. > > for(local $b=0; $b<=23; $b++){ > > local $hour = $b+1; > local $root = 'data.hr'; > local $name = "$root$hour"; > > for(local $i=0; $i<=1847; $i++){ > > $specSum{$name}[$i] = $specSum{$name}[$i] + $hrHash{$name}[$i]; > > } > > }
I could be blind (wouldn't be the first time!), but I don't see the problem with this code. I tightened it up a bit to try to reduce the scope of the issue to something more obvious: for my $hour ( 1..24 ) { my $name = "data.hr$hour"; for my $i ( 0..1847 ) { $specSum{$name}[$i] += $hrHash{$name}[$i]; } } That appears to have the same functionality as your original code. It doesn't seem to have anything wrong with it. Perhaps the error lies elsewhere? There's nothing wrong with using variables as hash keys. Cheers, Curtis "Ovid" Poe ===== Senior Programmer Onsite! Technology (http://www.onsitetech.com/) "Ovid" on http://www.perlmonks.org/ __________________________________________________ Do You Yahoo!? NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. http://geocities.yahoo.com/ps/info1 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]