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 :)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|