in reply to Re: Comparing 1 list and 1 array
in thread Comparing 1 list and 1 array
Thanks everyone for your help. I had wondered about using a %file, but I wanted a 2 dimentional array, so figured that would be how to get one. :/
I have taken out reading into $file, and opened the list straight into INFO, and gone with a hash table.
My teammates asked that I print the IP if I couldn't find it in the table, so I added an else.
I'm still working on the hash table, to make sure I don't need more than those 2 fields.
Its been over 10 years since I did any Perl scripting, so I am WAY out of practice!
Here is the second interation of code:
#!/perl
#
open(INFO, '<IPs.txt' ) or die;
@lines1 = <INFO> ;
close(INFO) ;
my %table
open(IN, '<source.txt' ) or die;
while (<IN>) {
chomp;
my($ip, $country) = split(' ',$_,2);
$table($ip) = $country;
}
open(OUT, ">>conversion.txt") or die;
foreach $line1 (@lines1)
{
if (exists $table($line1))
{
if $line2 =~ /$line1/ ;
print OUT $line1, ' ',$table($line1),"\n" ;
else
else
print OUT $line1;
}
}
close OUT;