in reply to Comparing 1 list and 1 array
is incorrect. You should use a '$' here, not a '%', since file2 is holding a simple string. For that matter, you could reuse $file1 from the previous block of code, or do without storing the filename in a variable altogether:%file2 = 'Source.txt' ; open(INFO, "<%file2" ) ;
open(INFO, '<Source.txt');
You'll have to make sure that split() call correctly splits your input data into IP and country name, of course.my %table; open(IN, '<Source.txt') or die; while (<IN>) { chomp; my($ip, $country) = split(' ', $_, 2); $table{$ip} = $country; }
Once you've done that--and assuming you've removed newlines from your input data--you can do country lookups like this:
open(OUT, '>>conversion.txt') or die; foreach $line1 (@lines1) { if (exists $table{$line1}) { print OUT $line1, ' ', $table{$line1}, "\n"; } } close OUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Comparing 1 list and 1 array
by Anonymous Monk on Jun 25, 2002 at 17:50 UTC |