develooper Front page | perl.beginners | Postings from December 2002

RE: populating a hash key using a variable

Thread Previous | Thread Next
From:
Kipp, James
Date:
December 11, 2002 08:11
Subject:
RE: populating a hash key using a variable
Message ID:
EC6C49DE5C846143AA2CE580420E77C331D28B@xexwlm05.mbnainternational.com
> 
> If I do $hash{SOMETHING}{0} = $something;
> 
> Then my hash is populated correctly.  I am only not getting 
> results if I 
> do $hash{SOMETHING}{$i} = $something.  The key here is how I am using 
> the variable $i in my hash.
> 
>

I tried this on my machine and it worked fine:
my $i;
for ( 1..5 ) {
       $hash{'KEY'}{$i} = "test$i";
	 print "$hash{'KEY'}{$i}\n";
       $i++;
} 
# prints:
test
test1
test2
test3
test4


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About