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: Removal of duplicated element in array with order.: Edit Log



Wazezu
Novice

May 6, 2013, 8:19 AM


Views: 1239
Removal of duplicated element in array with order.

The following is the code for removing duplicated data, but it doesn't work.

The output is exactly the same as the input with duplicated elements.

Many thanks.


Code
#$1 is the matched regex, including duplicated elements. 

#$1 contains
#dmit@sp.com
#ems@es.com
#dew@es.com
#dmit@sp.com
#erg@es.com

my $match = $1."\n";

my @match_to_array = split("(\n)",$match);

my %seen = ();
my @r = ();

foreach my $a (@match_to_array) {
unless ($seen{$a}) {
push @r, $a;
$seen{$a}++;
}
}
print @r;



(This post was edited by Wazezu on May 6, 2013, 8:19 AM)


Edit Log:
Post edited by Wazezu (Novice) on May 6, 2013, 8:19 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