in reply to how to include an array of hashes in a hash of hashes?
G'day anadem,
"Please advise me on how to structure my data."
I don't think there's anything wrong with your current structure, except that you need one per component=XXX with each being held in another hash whose keys are the XXX values.
Here's how I produced that:
$ perl -Mstrict -Mwarnings -e ' use Data::Dumper; my @data = qw{ 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 }; my (%compdata, $comp, $file); for (@data) { my ($key, $value) = split /=/; for ($key) { /component/ && do { $comp = $value; last }; /version/ && do { $compdata{$comp}{version} = $value; l +ast }; /sourcefile/ && do { $file = $value; last }; /sourcesum/ && do { $compdata{$comp}{sources}{$file} = $v +alue }; } } print Dumper \%compdata; ' $VAR1 = { 'SVM' => { 'version' => '10.0.70.102', 'sources' => { 'filename4' => 'checksumfile4' } }, 'HF' => { 'version' => 'NULL', 'sources' => { 'filename3' => 'checksumfile3', 'filename2' => 'checksumfile2', 'filename1' => 'checksumfile1' } } };
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to include an array of hashes in a hash of hashes?
by anadem (Scribe) on Sep 17, 2013 at 17:42 UTC | |
|
Re^2: how to include an array of hashes in a hash of hashes?
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 |