Firstly, you have no duplicates in any (of what you're calling) "scope".
G123465798 is not a duplicate of G123456798: you've transposed the 5 and the 6.
I've fixed this in the example below.
There's a standard idiom for checking for duplicates in this sort of scenario.
Use a hash (often called %seen) that has as its keys whatever identifier you're checking.
While processing, if the key exists, it's a duplicate, so skip/flag/etc. as appropriate;
if the key doesn't exist, it's unique, so use it and then add it to the hash (usually done with a postfix increment).
Here's an example using your fixed data:
#!/usr/bin/env perl -l
use strict;
use warnings;
my @data = (
[ qw{E123456789 G123456798 h12345} ],
[ qw{E1234567 E7899874 G123456798 G123456789 G123456798 h1245} ],
);
for my $scope (@data) {
my %seen;
for my $identifier (@$scope) {
print $identifier unless $seen{$identifier}++;
}
}
Output:
E123456789
G123456798
h12345
E1234567
E7899874
G123456798
G123456789
h1245
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|