in reply to How to do with this hash?
This takes advantage of the lookup capabilities of hashes.$CountryName = $CountryCode{$Country} || undef;
I'll be back in a minute with some more code... Here ya go:
#!/bin/perl -w use strict; use Socket; my $ip_addr = '207.127.235.77'; my $remote_host = gethostbyaddr(inet_aton($ip_addr),AF_INET); # get ww +w.xxx.xxx.uk my %CountryCode = ( 'com','Comercial', 'uk','The United Kingdom' ); # a hash of country names my @CCode = split /\./, $remote_host; # split every portion my $Country = $CCode[-1]; # get the last my $CountryName = $CountryCode{$Country} || "Country Unknown"; print $CountryName;
|
|---|