Dear Perl Monks. I have collected bunch of arrays that first element of each array should be a key I would like to produce print out like bellow. Do you have more elegant solution ? I will appreciate
ArrA = qw(A 1 2 3 4 5); ArrB = qw(B 1 2 5 6); ArrC = qw(C 2 3); for ($i=1; $i < 6; $i++) { push(@{$CAPABILITIES{$ArrA[$i]}}, $ArrA[0]); push(@{$CAPABILITIES{$ArrB[$i]}}, $ArrB[0]); push(@{$CAPABILITIES{$ArrC[$i]}}, $ArrC[0]); } foreach $key (sort (keys %CAPABILITIES)) { print "$key => "; foreach $role (sort @{$CAPABILITIES{$key}}) { print "$role "; } print "\n"; } # Desired Printout =begin COMMENT Key/Value ====================== 1 => A B 2 => A B C 3 => A C 4 => A 5 => A B 6 => B OR Key/Value A B C ====================== 1 X X 2 X X X 3 X X 4 X 5 X X 6 X =end COMMENT =cut
(: Life is short enjoy it :)

In reply to Multiple arrays in a hash by gasho

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.