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:
how to find the duplicate in array

 



aanpudur
New User

Dec 1, 2009, 5:55 PM

Post #1 of 4 (664 views)
how to find the duplicate in array Can't Post

Could anyone please help me how to find duplicate array using hash table? I am a beginner, could you please explain to me?


7stud
Enthusiast

Dec 1, 2009, 10:13 PM

Post #2 of 4 (660 views)
Re: [aanpudur] how to find the duplicate in array [In reply to] Can't Post


Code
use strict; 
use warnings;
use 5.010;

my @arr = ('a', 'b', 'c', 'b', 'b', 'c');
my %hash;

for (@arr) {
$hash{$_}++;
}

say %hash;

--output:--
c2a1b3



aanpudur
New User

Dec 1, 2009, 10:40 PM

Post #3 of 4 (656 views)
Re: [7stud] how to find the duplicate in array [In reply to] Can't Post

Thank you very much. I really appreciate it.

If you have time and you could explain that would be great


7stud
Enthusiast

Dec 2, 2009, 7:48 AM

Post #4 of 4 (635 views)
Re: [aanpudur] how to find the duplicate in array [In reply to] Can't Post


Code
use strict; 
use warnings;
use 5.010;

my @arr = ('a', 'b', 'c', 'b', 'b', 'c');
my %hash = (
a => 0,
b => 0,
c => 0
);

for my $letter (@arr) {
my $count = $hash{$letter};
$hash{$letter} = $count + 1;
}

say %hash;

--output:--
c2a1b3


 
 


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

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