Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Detecting duplicate entries

by davorg (Chancellor)
on Mar 01, 2001 at 22:09 UTC ( [id://61602]=note: print w/replies, xml ) Need Help??


in reply to Detecting duplicate entries

The hash solutions that have already been given have the right idea, but you can use hash slices to make it look a bit simpler.

my %uniq; @uniq{@orig_list} = @orig_list; my @unique_list = keys %uniq;
--
<http://www.dave.org.uk>

"Perl makes the fun jobs fun
and the boring jobs bearable" - me

Replies are listed 'Best First'.
Re: Re: Detecting duplicate entries
by japhy (Canon) on Mar 01, 2001 at 22:24 UTC
    Don't assign values, just assign ().

    Or use:

    $seen{$_}++ or push @uniq, $_ for @orig; # or @uniq = grep !$seen{$_}++, @orig;


    japhy -- Perl and Regex Hacker
Re: Re: Detecting duplicate entries
by petral (Curate) on Mar 01, 2001 at 23:48 UTC
    And probably even slower, but it avoids the %temp and it's cute:
    sort keys %{ { map { $_ => 1 } @orig_list }

    p
        Ok, but it keeps up with sort -u above.

        p
Re: Re: Detecting duplicate entries
by merlyn (Sage) on Mar 01, 2001 at 22:11 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found