Hello , Here is a code that is supposed to generate union of two array. The error with this code is that, the generated array contains redundent info which is not desired . Kindly identify the error and suggest solution..
Thanks in advance..
my @arr_in_1 =("User1","user2","user3");
my @arr_in_2 =("user2","user3","User4");
my @union_arr;
foreach my $arr_1(@arr_in_1)
{push(@union_arr,$arr_1);}
foreach my $arr_1(@arr_in_1)
{
#print "The value in array 1 is :" .lc $arr_1."\n";
foreach my $arr_2(@arr_in_2)
{
#print "the value in array 2 is :". lc $arr_2." \n";
if (lc $arr_2 ne lc $arr_1)
{
push(@union_arr,$arr_2);
}
}
}
print "union array @union_arr";
Edit kudra,
2002-10-27
Added code tags
Anandatirtha
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.