mooseboy has asked for the wisdom of the Perl Monks concerning the following question:
I would like to build this into a hash of hashes thus:Q4_2001: 741 1203 3406 1861 1242 1911 601 etc Q3_2001: 773 1255 3552 1941 1296 1993 627 etc Q2_2001: 805 1307 3698 2021 1350 2075 653 etc
However, I am fairly new to Perl, and my attempts to write a sub to generate this HoH have not met with success, even after much perusal of perldsc, perllol, etc. Here's what I have so far:%HoH = ( Q4_2001 => { Algeria => 741, Argentina => 1203, etc }, Q3_2001 => { Algeria => 773, Argentina => 1255, etc }, );
I would be grateful for any brotherly advice as to where I am going wrong. Humble thanks in advance.sub build_HoH { while (<DATA>) { next unless s/^(.*?):\s*//; my $period = $1; my @data = split; foreach my $country(@countries) { $HoH{$period}{$country} = $data; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: building a hash of hashes with constant keys
by Zaxo (Archbishop) on Nov 19, 2002 at 09:43 UTC | |
by mooseboy (Pilgrim) on Nov 19, 2002 at 21:03 UTC | |
|
Re: building a hash of hashes with constant keys
by robartes (Priest) on Nov 19, 2002 at 09:05 UTC | |
|
Re: building a hash of hashes with constant keys
by Three (Pilgrim) on Nov 19, 2002 at 14:24 UTC |