Perl problem (foreach)

Associate
Joined
27 Jun 2006
Posts
1,473
Guys,

Doing a simple little perl script that takes a list of IP addresses from a form textbox and then showing what country they are for. Only problem is the Perl only seems to process the last element of the array!!!

Anyone see what is wrong before I rip the last few tufts of hair out?

Form:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>IP Country Checker</TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>

 <BODY>

 <form action="getcountry.pl" method="POST">  
	<textarea cols="15" rows="4" name="ipaddresses"></textarea>
	<input type="submit"><p>
 </form>


 </BODY>
</HTML>
[/FORM]

Perl code is:
Code:
#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use IP::Country::Fast;

$input = param('ipaddresses');
@address = split /\cM\cJ/, $input;

print header(); 
print start_html();

foreach (@address) 
{
	$reg = IP::Country::Fast->new();
	print $_." :: ".$reg->inet_atocc($_)."<br>";
}

print end_html();

Anything obvious???

Cheers!!
 
Cheers for that Jim,

Think it was the way I was testing in the end.
Being stupoid I just dumped in my real IP to check along with a couple of dummy IP addresses (1.1.1.1 & 2.2.2.2).

I thought all IP addresses would have a country and those two didn't so gave me a blank country code back!!!!!

Damn my dozy brain :)

Have slipped the 'my' in there as well anyway.

M.
 
Back
Top Bottom