Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making an array with unique numbers

Status
Not open for further replies.

thendal

Programmer
Aug 23, 2000
284
Hey guys!

Iam trying to make an array values as unique.

for example iam having an array

@a=(1,2,3,4,4,5)

I need an output @a=(1,2,3,4,5);

I tried like this.

for($i=0;$i<@a;$i++)
{
for($j=$i+1;$j<@a;$j++)
{
if($i eq $j)
{
splice(@a,$j,1);
}
}
}

using this i got the output 12345


But when i change the array values to some thing like this

@a=(1,2,3,4,4,4,4,4,4,4,5)

its giving an output not with the unique values

@a=(1,2,3,4,4,4,5)

I know iam missing some where in logic ,I hope u can help me.




[sig][/sig]
 
I'm flattered you thought my solution was good enough to go into a FAQ. I got the idea from the perlfunc man page description of the map function. (You all have read the perl man pages, haven't you?)
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top