in reply to Re: Removing Duplicate Array Elements!!!
in thread Removing Duplicate Array Elements!!!
Here is efficient way to remove dup elements in array, Every element is stored in a hash with key as the array element and value as 1. Since a hash cannot have duplicate keys, after populating the hash, the keys from the hash will consist of distinct array elements.my @dup_array = qw\sridhar sridhar guru chan guru hubli hubli hubli hu +rryo\; my %unique_hash; foreach my $x (@dup_array) { $unique_hash{$x} = 1; } @dup_array = keys %unique_hash; print "\n\n\n@dup_array";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Removing Duplicate Array Elements!!!
by Athanasius (Archbishop) on Sep 24, 2015 at 12:57 UTC | |
|
Re^3: Removing Duplicate Array Elements!!!
by Anonymous Monk on Sep 24, 2015 at 12:25 UTC |