in reply to finding the first unique element in an array
Instead of remembering the elements in @uniq, directly print them out:
my @uniq; my %seen = (); for my $i (0..$#name1) { if (!$seen{$name1[$i]}) { push (@uniq, $name1[$i]); print "$name1[$i]\t$name2[$i]\t$percent[$i]\n"; }; }
As an aside, I've removed your C-style loop, which is error-prone, and changed it into a more perlish loop.
Your data structures also scream for a hash, as using parallel arrays also is error prone; it's not always convenient to rearrange your data into concentrated data structures, especially if the arrays get filled from separate data streams.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: finding the first unique element in an array
by Anonymous Monk on Jul 19, 2005 at 10:02 UTC | |
|
Re^2: finding the first unique element in an array
by Limbic~Region (Chancellor) on Jul 19, 2005 at 14:45 UTC |