nashkab has asked for the wisdom of the Perl Monks concerning the following question:
Monks, I have two arrays @union and @ICUNAV.
@union = ((SDT,`1781183799.44927\',-----), (BN,`1781183799.44972\',-----), (BNN,`1781183799.46753\',-----)); @ICUNAV = ((BN,`1781183799.44972\',-----), (BNN,`1781183799.46753\',-----),(SFG,`1781183799.46753\',-----));
I am trying to find the new elements in @ICUNAV which dows not exist in @union. The result i am getting is:
@diff = ((SDT,`1781183799.44927\',-----), (SFG,`1781183799.46753\',-----));
What I want is
@diff = (SFG,`1781183799.46753\',-----);
my @diff; my @inter; my %count2 = (); foreach my $element (@union,@ICUNAV) { $count2{$element}++; }; foreach my $element (keys %count2) { push @{ $count2{$element} > 1 ? \@inter : \@diff }, $element; }; print Dumper(@diff),"\n";
I am new in Perl.Your help will be appreciated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Array Difference for Two Dimentional Array!
by NetWallah (Canon) on Jan 07, 2008 at 01:05 UTC | |
by nashkab (Novice) on Jan 07, 2008 at 01:16 UTC | |
by swampyankee (Parson) on Jan 07, 2008 at 02:27 UTC | |
by NetWallah (Canon) on Jan 07, 2008 at 05:37 UTC | |
|
Re: Array Difference for Two Dimentional Array!
by ysth (Canon) on Jan 07, 2008 at 01:53 UTC |