The data comes from a plain text file supplied in this format (no choice), one data item per line. (Filenames and checksum filenames are long URLS, so can't be conveniently placed on the same line but the source file URL line is immediately followed by the line with the URL for its checksum file):component => { version => "1.23.4.567", sources => { "filename1" => "checksumfile1", "filename2" => "checksumfile2", "filename3" => "checksumfile3", }
My attempted code is like this:component=HF version=NULL sourcefile=filename1 sourcesum=checksumfile1 sourcefile=filename2 sourcesum=checksumfile2 sourcefile=filename3 sourcesum=checksumfile3 component=SVM version=10.0.70.102 sourcefile=filename4 sourcesum=checksumfile4
Unfortunately (of course) the data for sources 1 and 2 is overwritten by source 3, so I think I need an array of source hashes, but I can't figure out how to code it thus this plea for help, kind monks.use strict; use Data::Dump qw(dump); my %HoH = (); my $rec; my $component; while ( <DATA> ) { chomp; next unless m/^\S+/; if( m/^component=(.*)/ ) { $component = $1; $rec = {}; $HoH{$component} = $rec; } elsif( m/^version=(.*)/ ) { $rec->{"version"} = $1; } else { my ($key, $value) = split /=/; $rec->{$key} = $value; } } for my $component ( keys %HoH ) { print "$component: "; for my $key ( keys %{ $HoH{$component} } ) { print "$key=$HoH{$component}{$key} "; } print "\n"; } dump %HoH; __DATA__ component=HF version=NULL sourcefile=filename1 sourcesum=checksum1 sourcefile=filename2 sourcesum=checksum2 sourcefile=filename3 sourcesum=checksum3 component=SVM version=10.0.70.102 sourcefile=filename4 sourcesum=checksum4
In reply to how to include an array of hashes in a hash of hashes? by anadem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |