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"; }

In reply to Re: how to include an array of hashes in a hash of hashes? by tangent
in thread how to include an array of hashes in a hash of hashes? by anadem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.