Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Getting rid of duplicates

by rlb3 (Deacon)
on Sep 29, 2004 at 14:12 UTC ( [id://394985]=note: print w/replies, xml ) Need Help??


in reply to Getting rid of duplicates

Hello,

You may want to use hashes.

This is untested.
my %store; foreach (<DATA>) { chomp; $store{$_} = 1; } print join ",", keys %store; __DATA__ 1236 3232 1236 4323 4323
Something like that may work for you.

rlb3

Replies are listed 'Best First'.
Re^2: Getting rid of duplicates
by JediWizard (Deacon) on Sep 29, 2004 at 14:28 UTC

    I have a utility function I often use for this sort of thing. See Below:

    my(@numbers) = <DATA>; chomp @number; print join("\n", uniqStrings(@numbers)); sub uniqStrings { my %temp = (); @temp{@_} = (); return keys %temp; } __DATA__ 1236 3232 1236 4323 4323

    That will actually run a little faster because the method used to remove duplicate numbers is pretty well optimized. Hope that helps.

    May the Force be with you

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-18 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found