Skip to content

Instantly share code, notes, and snippets.

Last active Feb 9, 2019
What would you like to do? - Perl Example Postcode Lookup
# Kindly provided by github/@digdilem
my $pc = "TQ13 9XT"; # Example postcode (Dartmoor National Park Visitor's Centre, Haytor)
use LWP;
use JSON qw( decode_json );
my $ll_url = "$pc";
my $ua = LWP::UserAgent->new;
$ua->agent("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv: Gecko/20080623 Firefox/");
my $req = HTTP::Request->new(GET => $ll_url);
my $response = $ua->request($req);
if ($response->is_success) {
my $json = decode_json( $response->content );
my $lat = $json->{'result'}{'latitude'};
my $lng = $json->{'result'}{'longitude'};
print "Lat/lang = $lat / $lng \n";
} else {
print "Failure in lookup \n"; return;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment