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:
Looking for duplicates

 



Alexey
Novice

Dec 27, 2007, 9:55 AM

Post #1 of 6 (813 views)
Looking for duplicates Can't Post

I have an array that contains comma separated strings. The strings represent parameters for a router access list. Second and fourth parameters are source and destination IP addresses. I am looking to create another array with a unique combination of source and destination IPs (combination of parameter 2 and 4 ).
Here is what array looks like
$array[0] = tcp,1.2.3.4,,,5.6.7.8,,123
$array[1] = tcp,1.2.3.4,,,5.6.7.8,,456
$array[2] = tcp,1.2.3.5,,123,5.6.7.8,,
$array[3] = tcp,1.2.3.5,,1234,5.6.7.8,,
$array[4] = tcp,1.2.3.6,,456,5.6.7.8,,
Please note that the lines do not have duplicates.

What is the best way to parse out the the uniqe combinations of 2 ip addresses?
Thanks


KevinR
Veteran


Dec 27, 2007, 10:10 AM

Post #2 of 6 (812 views)
Re: [Alexey] Looking for duplicates [In reply to] Can't Post

Use a hash
-------------------------------------------------


Alexey
Novice

Dec 27, 2007, 4:41 PM

Post #3 of 6 (810 views)
Re: [KevinR] Looking for duplicates [In reply to] Can't Post

What if i decide to use combination of 3 fields in the future (to include destination port for example)?
Thanks


KevinR
Veteran


Dec 27, 2007, 10:32 PM

Post #4 of 6 (807 views)
Re: [Alexey] Looking for duplicates [In reply to] Can't Post

You probably still would use a hash. Hashes are very good for finding/removing duplicate data.
-------------------------------------------------


Alexey
Novice

Dec 29, 2007, 10:13 AM

Post #5 of 6 (801 views)
Re: [KevinR] Looking for duplicates [In reply to] Can't Post

Kevin, can you provide a pseudo code for that? I have some ideas, but not sure if it is the most efficient way of doing it (using regex searches, using references, looking for duplicate before adding, if i should create some sort of object) . I haven't done much Perl programming so i am not sure about the most efficient ways of doing things.
Thanks


KevinR
Veteran


Dec 29, 2007, 11:01 AM

Post #6 of 6 (799 views)
Re: [Alexey] Looking for duplicates [In reply to] Can't Post

Read the FAQs on this page:

http://perldoc.perl.org/perlfaq4.html

The Data:Arrays section might help you the most with the information you want.
-------------------------------------------------

 
 


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

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