The most natural way to generalize the code IMHO is to change to a loop over array references rather than treating each array individually - see
perlreftut. You could put this all in a complex data structure (
perldsc) rather than how you have it loaded now, but you could generalize what you have as something like:
if (($Entry > 0) && ($ID[$Entry] eq $ID[$Entry - 1])) {
for my $ref (\@Value_1,
\@Value_2,
\@Value_3,
\@Value_4,
\@Value_5,
\@Value_6,
\@Value_7,
) {
if ($ref->[$Entry] =~ m/($ref->[$Entry - 1])/) {
$Placeholder = join(' / ', $ref->[$Entry], $ref->[$Entry - 1]
+);
delete $ref->[$Entry - 1];
push(@Value, $Placeholder);
}
}
}
Of course, the above is buggy since your posted code was already buggy -- you've got index problems on your counter as soon as you start deleting elements, and that push isn't helping. Also note the added comma in your join. But the loop should answer your question.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.