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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |