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

Re: populating a hash key using a variable

Thread Previous | Thread Next
Ian Zapczynski
December 11, 2002 07:40
Re: populating a hash key using a variable
Message ID:
I am not populating from a file, actually.  I'm populating from the 
output of $sth->fetch from DBI.  The $something and $something_else 
variables in this case are numbers which have been defined by the output 
of that method.  

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.


Kipp, James wrote:

>>Hello all,
>>I'm obviously making a silly mistake here and would appreciate it if 
>>someone can point out my error.  I am trying to populate a hash of a 
>>hash in a while() loop.  Here is what I have:
>>my $i = 0;
>>my %hash = ();
>>while (<EXPR>) {
>>        $hash{SOMETHING}{$i} = $something;
>>        $hash{SOMETHING_ELSE}{$i} = $something_else;
>>        $i++;
>>The $something and $something_else strings are properly 
>>defined.  If I 
>>check if $hash{SOMETHING}{$i} is defined or attempt to print it, it 
>>appears to be undefined.
>looks like you are trying to populate a hash of hashes from a file, what do
>the lines of the file look like? what is the $something and $something_else
>variables ?

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About