Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello
I have a list of IP addresses. In another file, I have another list of IP addresses, and the country from which they originate. I have keyed the array off the IP address.
What I need to do is take the IP in the first file, compare it to the second file, and then pull the associated country of origin from the second array. To make this easier, I am just pulling the entire line of the array, both IP and country.
I want to output this into a destination file.
This is what I've gotten so far. Am I doing this incorrectly?
Thank you#!/perl # $file1 = 'IPs.txt' ; # Name the file with IP addresses to be l +ooked up open(INFO, "<$file1" ) ; # Open the file @lines1 = <INFO> ; # Read it into an array close(INFO) ; # Close the file %file2 = 'Source.txt' ; # Name the file with source addresses open(INFO, "<%file2" ) ; # Open the file @lines2 = <INFO> ; # Read it into a two dimentional array close(INFO) ; # Close the file foreach $line1 (@lines1) # assign @lines1 to $line1, one at a time { foreach $line2 (@lines2) # assign @lines2 to $line2, one at a time { while $line1 != $line2 ; # Compare the entry from log gr +oup to source group { open(APPEND, ">>conversion.txt") ; print(APPEND "$line2" ; close(APPEND); } } }
updated by boo_radley : formatting, code tags.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Comparing 1 list and 1 array
by kjherron (Pilgrim) on Jun 24, 2002 at 22:19 UTC | |
by Anonymous Monk on Jun 25, 2002 at 17:50 UTC | |
|
Re: Comparing 1 list and 1 array
by bronto (Priest) on Jun 25, 2002 at 07:53 UTC | |
|
Re: Comparing 1 list and 1 array
by kvale (Monsignor) on Jun 24, 2002 at 22:15 UTC | |
by kjherron (Pilgrim) on Jun 24, 2002 at 22:45 UTC | |
|
Re: Comparing 1 list and 1 array
by caedes (Pilgrim) on Jun 25, 2002 at 00:59 UTC | |
by valdez (Monsignor) on Jun 25, 2002 at 12:57 UTC |