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.
In reply to Comparing 1 list and 1 array by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |