Home: Perl Programming Help: Beginner:
Passing an input file to my geoip script



starchon
New User

Nov 21, 2013, 4:12 AM


Views: 1276
Passing an input file to my geoip script

Hi, and thanks in advance for any responses.

I am following the tutorial on Geo::IP at drdobbs website. My code is below:


Code
#!/usr/bin/perl 

use Geo::IP;

my $gip = Geo::IP->new();

while( <> )
{
my( $ip ) = split;

my $country = $gip->country_name_by_addr( $ip );

$Countries{ $country }++;
}

foreach my $ip ( sort keys %Countries )
{
printf "%6d %s\n", $Countries{ $ip }, $ip;
}


When I run the script it just hangs - no output no error messages. It seems to me that I am not passing an input file to the script to split. I am unsure how to do this. ANY advice would be much apreciated.

Starchon


BillKSmith
Veteran

Nov 21, 2013, 5:24 AM


Views: 1272
Re: [starchon] Passing an input file to my geoip script

You have not shown us your command to run this script.

When your program appears to hang, it probably is waiting for input from your terminal. Refer to the section of perldoc perlop which discusses the operator <> with a null filehandle. (It should read from a file specified on the command line or STDIN if there is none)
Good Luck,
Bill


starchon
New User

Nov 21, 2013, 7:03 AM


Views: 1265
Re: [BillKSmith] Passing an input file to my geoip script

Many thanks - a bit more reading got me there in the end...
Blush