in reply to Re: How to stuff space separated column into Hash
in thread How to stuff space separated column into Hash

thanks marshall

Ideally, I'd like to use a Hash of Hashes and I have the following code

while ( my @row = $sth->fetchrow_array() ) { print ">@row<\n"; ($key, $value) = split ' ', $row[1]; $HoH{$row[0]}{$key} = $value; } while ( ($client, $months) = each %HoH ) { print "$client: "; while ( ($month, $count) = each %$months ) { print "$month=$count "; } print "\n"; }

the problem is the split to get the $key and $value only gets the first key->value pair. Is there a way to get all of the key-value pairs into the HoH?

Thanks!

Replies are listed 'Best First'.
Re^3: How to stuff space separated column into Hash
by dirtdog (Monk) on Aug 29, 2016 at 21:01 UTC

    I think I'm all set

    while ( my @row = $sth->fetchrow_array() ) { print ">@row<\n"; my %by_month = split ' ', $row[1]; $HoH{$row[0]} = \%by_month;

    This accomplishes my objective. Thanks again.

      Glad that you have something "that works".

      Since I see that you are using the DBI and SQL, I would use the power of SQL instead of trying to replicate this into a HOH. I actually was wondering what you did with for example 'IBM' as element 0. You can get the unique names of the companies, IBM,Oracle, etc. and then run SQL queries to get those company specific results.

      It looks like you may be trying to translate the entire SQL DB into a HoH memory array? I am quite sure that this will work for a spreadsheet. However for a big DB, that won't work and is not necessary.

      It appears to me that you need some more DBI "kung foo".