in reply to Comparing 1 list and 1 array

One problem is with
%file2 = 'Source.txt' ; # Name the file with source addresses open(INFO, "<%file2" ) ; # Open the file
The `%file' indicates a hash, not what you want here. Change it to
$file2 = 'Source.txt' ; # Name the file with source addresses open(INFO, "<$file2" ) ; # Open the file
To extract the countries, you need to see if the IP address in $line1 is contained in $line2:
open APPEND, ">>conversion.txt"; foreach $line1 (@lines1) { foreach $line2 (@lines2) { print APPEND $line2 if $line2 =~ /$line1/; } } close APPEND;
That code is still just a start. In addition you will want to check whether the open statements succeed and you will want to use perl -w to turn on warnings that can catch typos like %file above.

-Mark

Replies are listed 'Best First'.
Re: Re: Comparing 1 list and 1 array
by kjherron (Pilgrim) on Jun 24, 2002 at 22:45 UTC
    The code
    print APPEND $line2 if $line2 =~ /$line1/;
    is not a good way to look for an IP address in a line of text. First of all, it will match when you're searching for an IP that's a substring of the one contained in the text:
    $line1 = '1.2.3.4'; $line2 = '111.2.3.44'; print "match\n" if $line2 =~ /$line1/;
    Second, the periods in IP address strings will be interpreted as regular expression metacharacters:
    $line1 = '1.2.3.4'; $line2 = '11223344'; print "match\n" if $line2 =~ /$line1/;