I am using array util package for array comparison.I have reading two file single and single 2 in difference2.pl and comparing but it is showing the only the element present in array c.Plz tell me where I am doing mistake.
use Array::Utils qw(:all);
$file = 'single.txt';
open(FILE,$file);
@array= <FILE>;
#print @array;
$file1='single1.txt';
open(FILE1,$file1);
@array1=<FILE1>;
@d=@array1;
@c=@array;
print @d;
print @c;
# symmetric difference
@diff = array_diff(@a, @b);
# intersection
@isect = intersect(@c, @d);
#print @isect;
# unique union
@unique = unique(@a, @b);
#print @unique;
# check if arrays contain same members
if ( !array_diff(@a, @b) ) {
# do something
}
# get items from array @a that are not in array @b
@minus = array_minus( @c,@d );
print "\n difference";
print @minus;
I want the output of @minus.But is is showing the array c.
Single file contains element :1,2,3,4
Single1 file contains element :1,5,6,7
Ideally the output should be:2,3,4.
plz help me.
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.