- # Return nothing if no location_id could be found.
- return unless($location_id);
-
- # Close filehandle.
- close(ADDRESS);
-
- # Open the location database.
- open(LOCATION, "$geoip_database_dir/$location_database") or die "Could not open $geoip_database_dir/$location_database. $!\n";
-
- # Loop through the file.
- while(my $line = <LOCATION>) {
- # Remove newlines.
- chomp($line);
-
- # Split the line content.
- my ($geoname_id, $locale_code, $continent_code, $continent_name, $country_iso_code, $country_name, $is_in_european_union) = split(/\,/, $line);
-
- # Check if the correct location_id has been found.
- if ($geoname_id eq $location_id) {
- # Store the county code.
- $country_code = $country_iso_code;
-
- # Break loop.
- last;
- }
- }
-
- # Close filehandle.
- close(LOCATION);
-
- # Return the obtained country code.
- return $country_code;