Dear Perl Monks,

I have 7 different arrays. The first being an unique identifier and rest being its values. Example;

@ID = qw(1 1 2 3 4 4 6 6); @Value_1 = qw(a a a a a a a a ); @Value_2 = qw(b b b b b b b b ); @Value_3 = qw(c d c c c d c d);

If one of the IDs have more than one value in one of the arrays it appears more than one time in each section. Since 1 hac c and d value in @Value_3 it appears two times with the same value in ID Value_1 and Value_2. What is to get rid of redundancies and if there is a different value for single ID then merge it like "c / d".

What I tried is to go through all the IDs and if ID$n eq ID$n - 1 then check if each Value1_$n is ne Value_1$n - 1 have a separate variable to merge it delete $n - 1 and append the new one. The problem is the code is getting really long with 7+ columns. Is there a shorter way to do it? I realize my explanation might be vague.. Thanks for your help!

if (($Entry > 0) && ($ID[$Entry] eq $ID[$Entry - 1])) { if ($Value_1[$Entry] =~ m/($Value_1[$Entry - 1])/) { $Placeholder = join(' / '$Value_1[$Entry], $Value_1[$Entry - 1]); delete $Value[$Entry - 1]; push(@Value, $Placeholder); etc... }

In reply to Arrays merges and redundancies by Anonymous Monk

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.