Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: how to speed up dupe checking of arrays

by FunkyMonk (Canon)
on Jul 31, 2007 at 10:23 UTC ( #629788=note: print w/ replies, xml ) Need Help??


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";


Comment on Re: how to speed up dupe checking of arrays
Select or Download Code
Re^2: how to speed up dupe checking of arrays
by ultibuzz (Monk) on Jul 31, 2007 at 10:43 UTC

    i want non dupes but want to keep 1 of all the dupes.
    so 1 2 3 4 is waht i want ;D

    kd ultibuzz

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://629788]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-10-02 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (41 votes), past polls