Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Remove redundency from an array

by gube (Parson)
on Sep 24, 2007 at 15:02 UTC ( #640729=note: print w/replies, xml ) Need Help??


in reply to Remove redundency from an array

This below code also one of the method to avoid duplicate values from array. It's lengthy code, However, it's one of the alternate method.

my @array = (1,1,3,2,3,5,3,3,7,5,2); my (%ar_hash, @ar); for(@array) { next if($ar_hash{$_}++); push(@ar, $_); } print "@ar"; o/p : 1 3 2 5 7

Replies are listed 'Best First'.
Re^2: Remove redundency from an array
by jdporter (Canon) on Sep 24, 2007 at 19:01 UTC

    Doesn't need to be lengthy.

    my @u = do { my %seen; grep { ! $seen{$_}++ } @a };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2016-09-27 00:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (493 votes). Check out past polls.