Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Remove the duplicate data from array using perl

rajeshkumar created the topic: Remove the duplicate data from array using perl

Remove the duplicate data from array using perl

Method 1
============================================
sub uniqueentr
{
return keys %{{ map { $_ => 1 } @_ }};
}

@array = ("perl","php","perl","asp”);

print join(" ", @array), "\n";
print join(" ", uniqueentr(@array)), "\n";

Method 2
============================================
sub uniq {
return keys %{{ map { $_ => 1 } @_ }};
}

@my_array = ("one","two","three","two","three");
print join(" ", @my_array), "\n";
print join(" ", uniq(@my_array)), "\n";

Method 3
============================================
sub uniq2 {
my %seen = ();
my @r = ();
foreach my $a (@_) {
unless ($seen{$a}) {
push @r, $a;
$seen{$a} = 1;
}
}
return @r;
}
@my_array = ("one","two","three","two","three");
print join(" ", @my_array), "\n";
print join(" ", uniq2(@my_array)), "\n";

Method 4
============================================
my %unique = ();
foreach my $item (@myarray)
{
$unique{$item} ++;
}
my @myuniquearray = keys %unique;

Method 5
============================================
sub duplicate {
my @args = @_;
my %items;
for my $element(@args) {
$items{$element}++;
}
return grep {$items{$_} > 1} keys %items;
}

Method 6
============================================
#! /usr/bin/perl -w

use strict;

sub uniq{
my %temp_hash = map { $_, 0 } @_;
return keys %temp_hash;
}

my @test_array = qw/ 1 3 2 4 3 2 4 7 8 2 3 4 2 3 2 3 2 1 1 1 /;
my @uniq_array = uniq(@test_array);
print "@uniq_array\n";

Method 7
============================================
%seen=();
@unique = grep { !$seen{$_} ++ } @array;

Method 8
============================================
my @in=qw(1 3 4 6 2 4 3 2 6 3 2 3 4 4 3 2 5 5 32 3); #Sample data
my @out=keys %{{ map{$_=>1}@in}}; # Perform PFM
print join ' ', sort{$a<=>$b} @out;# Print data back out sorted and in order.

Reference:
Different Source of Google Search

Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x