What is your desired output? Listing what should be in main1-join will do the trick.

Update: How's this?

use strict; use warnings; use Data::Dumper; # Inputs. my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],}, 'main2' => {'m2sec1'=> ['D','E','F'],},); my @seed = ( 'X','Y','Z' ); my $output_length = 3; # Create a work area since we can't # modify the existing content of %main. my %work; foreach my $mn ( keys %main ) { foreach my $msec ( sort keys %{$main{$mn}} ) { $work{"$mn-join"}{$msec} = [ @{$main{$mn}{$msec}} ]; } } # Repeatedly multiply matrices (in place). $output_length--; while ($output_length--) { foreach my $mn ( keys %work ) { foreach my $msec ( sort keys %{$work{$mn}} ) { my @store; foreach my $val1 ( @{$work{$mn}{$msec}} ) { foreach my $val2 ( @seed ) { push(@store, "$val1$val2"); } } $work{$mn}{$msec} = \@store; } } } # Merge output with %main. %main = (%main, %work); # Show updated %main. print(Dumper(\%main));

Update: A simpler variation:

use strict; use warnings; use Data::Dumper; # Inputs. my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],}, 'main2' => {'m2sec1'=> ['D','E','F'],},); my @seed = ( 'X','Y','Z' ); my $output_length = 3; # Multiply the seed vector with itself as much as requested. my @seedx = @seed; for ( 3 .. $output_length ) { my @input = @seedx; @seedx = (); foreach my $val1 ( @input ) { foreach my $val2 ( @seed ) { push(@seedx, "$val1$val2"); } } } # Multiply vectors against seed matrix. foreach my $mn ( keys %main ) { foreach my $msec ( sort keys %{$main{$mn}} ) { my $store = $main{"${mn}-join"}{$msec} = []; foreach my $val1 ( @{$main{$mn}{$msec}} ) { foreach my $val2 ( @seedx ) { push(@$store, "$val1$val2"); } } } } # Show updated %main. print(Dumper(\%main));

Update: If $output_length will always be 3:

use strict; use warnings; use Data::Dumper; my %main = ( 'main1' => {'m1sec1'=> ['A','B','C'],}, 'main2' => {'m2sec1'=> ['D','E','F'],},); my @seed = ( 'X','Y','Z' ); foreach my $mn ( keys %main ) { foreach my $msec ( sort keys %{$main{$mn}} ) { my $store = $main{"${mn}-join"}{$msec} = []; foreach my $val1 ( @{$main{$mn}{$msec}} ) { foreach my $val2 ( @seed ) { foreach my $val3 ( @seed ) { push(@$store, "$val1$val2$val3"); } } } } } # Show updated %main. print(Dumper(\%main));

In reply to Re^3: Accumulating a Hash from Pairwise Comparison by ikegami
in thread 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.