![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Oct 2005
Posts: 54
Rep Power: 4
![]() |
Unique array?
Hi everybody!
I have a question concering arrays.. Say I have the following array: (1,12) (1,13) (2,14) (2,15) (2,3) (2,16) (3,15) (3,3) (3,20) (3,5) (3,6) (3,20) Everything is OK except that pair (3,20) is repeated twice. How can I avoid it? 'Map' function is the answer? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
This may get you going...
my %hash = map { $_ => 1 } @array; my @array2 = sort keys %hash; Where array2 is your unique array...
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 134
Rep Power: 3
![]() |
A page from the Perl Cookbook:
http://www.unix.org.ua/orelly/perl/cookbook/ch04_07.htm |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Oct 2005
Posts: 54
Rep Power: 4
![]() |
array of arrays [correct topic]
Hi guys,
thanx for your time... I seem to have made a mistake here... What I have is an array of arrays that i want to make unique. That is, I have: @AoA=(["1","15"], ["2","5"], ["3","4"], ["3","5"], ["3","8"], ["3","5"], ["4","6"], ["4","5"]) and I want to remove array element ["3","5"] which is seen twice if you notice. Is that possible? I am confused with this! |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2006
Location: Macedonia
Posts: 12
Rep Power: 0
![]() |
grep and one hash would do just fine
@array = grep {!$hash{$_}++} @array; where %hash should be 'defined' as an empty hash () and @array is your array where you have duplicate elements. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|