in reply to Using a hash to store complex data
%hash only has one key (how useless!), so
is the same as@HoH{keys %hash} = values %hash
$HoH{$unit_num} = $hash{$unit_num};
As you can clearly see now, you completely replace all existing data for $unit_num every time you find a new record for $unit_num.
Change
to%hash = ( $unit_num => { $event_nm => [ $event_date ], }, ); @HoH{keys %hash} = values %hash
Thanks to autovivification, the above is short forpush @{ $HoH{$unit_num}{$event_nm} }, $event_date
$HoH{$unit_num} ||= {}; $HoH{$unit_num}{$event_nm} ||= []; push @{ $HoH{$unit_num}{$event_nm} }, $event_date;
Tip: Don't pass hashes and arrays to Dumper. Pass references to them:
print Dumper( \%HoH );
|
|---|