Hi,
I do not know what you changed, but taking your original program, changing the split pattern to /\n/ (and adding a few prints just to show the content of the various variables) show that this works perfectly.
my $match = "foo1\nfoo2\nfoo3\nfoo4\nfoo5\nfoo3\nfoo2";
print '$match = ', "\n", $match, "\n\n";
my @match_to_array = split /\n/, $match;
print '@match_to_array = ', "@match_to_array \n\n";
my %seen = ();
my @r = ();
foreach my $a (@match_to_array) {
unless ($seen{$a}) {
push @r, $a;
$seen{$a}++;
}
}
print '@r = ', "@r";
This is now the output:
$ perl remove_duplicates.pl
$match =
foo1
foo2
foo3
foo4
foo5
foo3
foo2
@match_to_array = foo1 foo2 foo3 foo4 foo5 foo3 foo2
@r = foo1 foo2 foo3 foo4 foo5
The duplicate values (foo3 and foo2) have been duly removed.