in reply to Re: finding the first unique element in an array
in thread finding the first unique element in an array
The object isn't to remove duplicates but to find the first entry that doesn't have a duplicate and then print the corresponding element (via the index) in another array.
It is completely possible that I am the one who has interpreted the problem wrong though.my (@name1, @name2, @percent); # initialized elsewhere my %seen; ++$seen{$_} for @name1; for ( 0 .. $#name1 ) { next if $seen{ $name[$_] } > 1; print $name2[$_]; last; }
Cheers - L~R
Update: Oversight corrected thanks to blazar below. That's what you get for not testing your code ;-)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: finding the first unique element in an array
by blazar (Canon) on Jul 19, 2005 at 14:43 UTC |