neversaint has asked for the wisdom of the Perl Monks concerning the following question:
And then accumulating the appended element into %main hash. Such that in the final result will give this:my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],}, 'main2' => {'m2sec1'=> ['D','E','F'],},); my %seed = ( 'seed' => {'seed1'=> ['X','Y','Z']},);
But how come my code below still doesn't do the job properly?my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],}, 'main2' => {'m2sec1'=> ['D','E','F'],}, 'main1-join' => { 'm1sec1'=> ['AX','BX','CX', 'AY','BY','CY', 'AZ','AY','AZ'], }, 'main2-join' => { 'm2sec1'=> ['DX','EX','FX', 'DY','EY','FY', 'DZ','EZ','FZ], } );
use Data::Dumper; my %nhash; foreach my $sd ( keys %seed ) { foreach my $sdsub ( sort keys %{$seed{$sd}} ) { my %temphash; foreach my $valseed ( @{$seed{$sd}{$sdsub}} ) { my $join; INNER: foreach my $mn ( keys %main ) { foreach my $msec ( sort keys %{$main{$mn}} ) { my @store; foreach my $valmain( @{$main{$mn}{$msec}} ) { #print $valmain.$valseed,"\n"; $join = $valmain.$valseed; push @store,$join; last INNER if (length($join) > 2); } $temphash{$msec} = [ @store ]; $main{$mn."-join"} = {%temphash}; } } #print "$valseed\n"; } } } print Dumper \%main ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Accumulating a Hash from Pairwise Comparison
by ikegami (Patriarch) on Sep 07, 2005 at 04:39 UTC | |
by neversaint (Deacon) on Sep 08, 2005 at 05:29 UTC | |
by ikegami (Patriarch) on Sep 08, 2005 at 14:36 UTC | |
|
Re: Accumulating a Hash from Pairwise Comparison
by GrandFather (Saint) on Sep 07, 2005 at 04:40 UTC | |
|
Re: Accumulating a Hash from Pairwise Comparison
by GrandFather (Saint) on Sep 07, 2005 at 05:52 UTC | |
|
Re: Accumulating a Hash from Pairwise Comparison
by injunjoel (Priest) on Sep 07, 2005 at 05:01 UTC |