I have an array called final_array.
The elements of the array are read from a text file.
How can i iterate through the array to remove duplicates?
Cheerz
Mark
Perl - Removing duplicates from an array
Moderator: General Moderators
if anyone is interested, thi is how you do it
Code: Select all
undef %saw;
@final_array = grep(!$saw{$_}++, @final_array);Code: Select all
my @arr = ('a', 'b', 'c', 'b', 'b', 'b', 'd', 'a', 'e' );
# here's the trick
@arr = do { my %seen; grep !$seen{$_}++, @arr };
foreach my $element (@arr) {
print $element, "\n";
}GAH! Edited because of stupidity.if it weren't about perl
Thanks volka. I was so thinking php here...
Last edited by JAM on Wed Aug 27, 2003 11:53 am, edited 1 time in total.