in reply to how to speed up dupe checking of arrays
Either @non_dupe_rows is very poorly named, or my @non_dupe_rows = do { my %seen;grep !$seen{$_}++, @rows }; isn't doing what you think it's doing:
my @rows = qw/ 1 2 3 4 1 2 /; # 1 & 2 are dups my @non_dupe_rows = do { my %seen;grep !$seen{$_}++, @rows }; print "@non_dupe_rows\n";
prints
1 2 3 4
If you really want non-dup rows, try
my @rows = qw/ 1 2 3 4 1 2 /; # 1 & 2 are dups my @non_dupe_rows = do { my %seen; $seen{$_}++ for @rows; grep $seen{$_} == 1, keys %seen }; print "@non_dupe_rows\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to speed up dupe checking of arrays
by ultibuzz (Monk) on Jul 31, 2007 at 10:43 UTC |