in reply to how to include an array of hashes in a hash of hashes?

I have had to make quite a few changes to your logic in order to get the desired result, but this works for the given input, and assumes that "the source file URL line is immediately followed by the line with the URL for its checksum file" is always the case.
use strict; use Data::Dumper; my %HoH = (); my $component; while ( my $line = <DATA> ) { chomp $line; next unless $line =~ m/^\S+/; if ( $line =~ m/^component=(.*)/ ) { $component = $1; next; } next unless $component; if ( $line =~ m/^version=(.*)/ ) { $HoH{$component}{"version"} = $1; next; } if ( $line =~ m/^sourcefile/ ) { my ($k, $key) = split(/=/,$line); # READ THE NEXT LINE $line = <DATA>; chomp $line; if ( $line =~ m/^sourcesum/ ) { my ($v, $value) = split(/=/,$line); $HoH{$component}{'sources'}{$key} = $value; } } } for my $component ( keys %HoH ) { my $hash = $HoH{$component}; my $version = $hash->{'version'} || ''; my $sources = $hash->{'sources'} || {}; print "$component: \n"; print "version = $version\n"; for my $key ( keys %{ $sources } ) { print "$key = $sources->{$key}\n"; } print "\n"; } print Dumper(\%HoH);

Output:
HF: version = NULL filename1 = checksum1 filename3 = checksum3 filename2 = checksum2 SVM: version = 10.0.70.102 filename4 = checksum4 'HF' => { 'version' => 'NULL' 'sources' => { 'filename1' => 'checksum1', 'filename3' => 'checksum3', 'filename2' => 'checksum2' }, }, 'SVM' => { 'version' => '10.0.70.102' 'sources' => { 'filename4' => 'checksum4' }, }
Note: this method does not keep the order of the sources. If you need to keep the order then save them as an array of arrays like so:
REPLACE $HoH{$component}{'sources'}{$key} = $value; WITH push( @{ $HoH{$component}{'sources'} }, [$key,$value] ); THEN ACCESS for my $source ( @{ $sources } ) { print "$source->[0] = $source->[1]\n"; }

Replies are listed 'Best First'.
Re^2: how to include an array of hashes in a hash of hashes?
by anadem (Scribe) on Sep 19, 2013 at 00:03 UTC
    thanks! I like the extra read, to validate correct order in the config spec. I'll use that along with Ken's data structuring.