G'day Doozer,
"I don't think I am adding the new details for each box to the hash correctly."
That's not your problem (although there's probably a better way to achieve this). See DB_File - "How do I store complex data structures with DB_File?":
Although DB_File cannot do this directly, there is a module which can layer transparently over DB_File to accomplish this feat.
Check out the MLDBM module, available on CPAN in the directory modules/by-module/MLDBM.
The value you're associating with each $hash{$location} is the stringified representation of the hashref { 'Date Active' => $date_active, ... } (i.e. HASH(0xhex-digits)) — this is the string you can't use as a hash reference.
Regarding my comment "there's probably a better way to achieve this", consider using a hash slice (see perldata - Slices) instead of assigning each element of @box to a separate variable which is subsequently used just once as a value. Here's an example using a cutdown version of your code and data:
$ perl -Mstrict -Mwarnings -E ' my @STB_keys = ("Date Active", "Manufacturer"); my %hash; my $line = "Zone1 - Box1,01/06/2011,Amstrad"; my @box = split /,/ => $line; my $location = shift @box; @{$hash{$location}}{@STB_keys} = @box; say $hash{"Zone1 - Box1"}{"Date Active"}; say $hash{"Zone1 - Box1"}{"Manufacturer"}; ' 01/06/2011 Amstrad
Also, splitting a CSV file on a comma will break if any value contains a comma: Text::CSV is a better choice.
-- Ken
In reply to Re: .csv file in to hash of hashes for a Berkley DB (for a hash newbie)
by kcott
in thread .csv file in to hash of hashes for a Berkley DB (for a hash newbie)
by Doozer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |