anadem has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to include an array of hashes in a hash of hashes?
by tangent (Parson) on Sep 16, 2013 at 23:09 UTC | |
by anadem (Scribe) on Sep 19, 2013 at 00:03 UTC | |
|
Re: how to include an array of hashes in a hash of hashes?
by kcott (Archbishop) on Sep 17, 2013 at 03:19 UTC | |
by anadem (Scribe) on Sep 17, 2013 at 17:42 UTC | |
by anadem (Scribe) on Sep 23, 2013 at 20:49 UTC | |
by kcott (Archbishop) on Sep 24, 2013 at 02:17 UTC | |
by anadem (Scribe) on Sep 27, 2013 at 02:52 UTC |