CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Wazezu] Removal of duplicated element in array with order.: Edit Log



Laurent_R
Veteran / Moderator

May 7, 2013, 2:38 AM


Views: 1213
Re: [Wazezu] Removal of duplicated element in array with order.


In Reply To
No =/. After changing the

Code
split

code like you recommended, the output is still the same.

Could this whole issue be due to my regex ?

I am extracting email addresses from an HTML file.


Code
\w[-.\w]*\@[a-z0-9]+(\.[-a-z0-9]+)*\.(com|edu|info|net|org|gov))/



Hi,

I post here again what I answered on your cross post on the Perl Monks.

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) shows that this works perfectly.




Code
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:



Code
$ 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.


(This post was edited by Laurent_R on May 7, 2013, 3:45 AM)


Edit Log:
Post edited by Laurent_R (Veteran) on May 7, 2013, 3:45 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives