Dear Masters,
I want to compare these two hashes in pairs. Basically by appending array element from %main with %seed in pairs.
my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],}, 'main2' => {'m2sec1'=> ['D','E','F'],},); my %seed = ( 'seed' => {'seed1'=> ['X','Y','Z']},);
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'],}, 'main1-join' => { 'm1sec1'=> ['AX','BX','CX', 'AY','BY','CY', 'AZ','AY','AZ'], }, 'main2-join' => { 'm2sec1'=> ['DX','EX','FX', 'DY','EY','FY', 'DZ','EZ','FZ], } );
But how come my code below still doesn't do the job properly?
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 ;


---
neversaint and everlastingly indebted.......

In reply to Accumulating a Hash from Pairwise Comparison by neversaint

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.