Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re:{3} Removing Duplicates in an array?

by jeroenes (Priest)
on Jun 26, 2001 at 19:36 UTC ( #91631=note: print w/ replies, xml ) Need Help??

in reply to Re: (jeffa) Re: Removing Duplicates in an array?
in thread Removing Duplicates in an array?

At 2818 chars, I golf:
sub u{@h{@_}=@_;keys%h} print join "\t", u("fish","bread","eggs","eggs","fish","butter") #butter bread fish eggs
/me wonders how soon MeowChow will have a shorter solution...

"We are not alone"(FZ)
Update: Too bad. The shortest I can come with is just a rewrite of Davorg's code (he's a golfer in disguise):

sub u{$h{$_}++for@_;grep$h{$_}<2,keys%h}

Replies are listed 'Best First'.
Re: Re:{3} Removing Duplicates in an array?
by Tiefling (Monk) on Jun 26, 2001 at 20:11 UTC
    Nice golf, jeroenes. Trouble is, (if your sample output is right) it answers the original question, not the one I posed as a golf. What's the shortest way to produce exactly the elements which occurs uniquely (ie: only once) in the original array? Davorg's code does the right thing, but it's a canonical answer, as he admits, rather than golf.

    Tiefling (Just Another Perl Newbie)

    -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GAT d++ s:- a-- C++ UL P++ L++(+) E? W+(++) N+ o? K w+(--) !O M- V? PS+ PE- Y PGP- t+ 5 X+ R+++ tv- b+++ DI++++ D+ G+ e++ h!(-) y +? ------END GEEK CODE BLOCK------
Re: Re:{3} Removing Duplicates in an array?
by MeowChow (Vicar) on Jun 27, 2001 at 11:16 UTC
    Well, I've already golfed it down to 30 chars, but I thought you might enjoy this rather bizarre one at 33:
    sub u { delete@h{grep$h{$_}++,@_};keys%h }
    As with yours, my%h; should really be prepended to make the sub reusable.
                   s aamecha.s a..a\u$&owag.print

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2016-08-28 09:17 GMT
Find Nodes?
    Voting Booth?
    The best thing I ever won in a lottery was:

    Results (392 votes). Check out past polls.