CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
deleting duplicates in two dimensional array

 



xsustek
New User

Dec 2, 2010, 12:01 PM

Post #1 of 2 (449 views)
deleting duplicates in two dimensional array Can't Post

Hi,

I have a two dimensinal array where I need to remove duplicate rows. I tried to find the algorithm, but with no success.

Does anyone know?


BillKSmith
Veteran

Dec 3, 2010, 8:33 AM

Post #2 of 2 (440 views)
Re: [xsustek] deleting duplicates in two dimensional array [In reply to] Can't Post

Strictly speaking, you cannot have a two dimensional array in perl. We simulate it very well with a list of lists. That is, we have list which contains references to other lists, each of which contains the data for one row. There are two ways you can have "duplicate rows". In one case you have two or more duplicate references which refer to the same list of row data. In the other case, you have references which refer to different lists which contain identical data. The second case is much more common.

You really have two problems. Find the duplicate and remove it. If you are sure that you have case 1, the find part can be much easier and faster, but an algorithm which does the find for case 2 will work for case 1. In either case, remove the reference with splice (refer perldoc -f splice).

I recommend using a CPAN module such as Array::Compare or List::Compare to do the actual compares.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives