| Number Portability Lookup - Sample Code for Carrier Query: PERL
  
 PERL Sample Code:
The following code sample demonstrates how to query the carrier of a mobile subscriber by phone number via the NumberPortabilityLookup query service using the Perl programming language. 
The code requires the perl LWP module to be installed; This can be installed using apt-get install libwww-perl on Debian or Ubuntu, or using the appropriate package manager for your system. It can also be found on CPAN, and in most standard perl distributions.
 
 Other Code Samples & Asterisk Carrier Lookup Examples
To find code samples for other languages, or number portability lookup integration examples for the Asterisk PBX, click here. 
 Code Sample:
#!/usr/bin/perl
# Sample Number Portability Lookup Query using Perl LWP
# This code may be freely adapted and used in any project or software in
# order to leverage a carrier lookup through numberportabilitylookup.com
# NPL Account Credentials - customise to your own account details
# Free trial account available at www.numberportabilitylookup.com
use LWP::UserAgent;
my $username  = "myusername";
my $password  = "mypassword";
print "Carrier query returned: ".lookupCarrier("447785123456")."\n";
exit;
sub lookupCarrier
{
	my $msisdn=shift;
	my $browser   = LWP::UserAgent->new;
	my $url       = "http://api.numberportabilitylookup.com/npl";
	my $queryData = "user=$username&pass=$password&msisdn=$msisdn";
	my $response  = $browser->post($url, content=>$queryData);
	my $content   = $response->content;
	my @dataLine=split("\n",$content);
	if ($dataLine[0] eq "QUERYOK")
	{
		($msisdn,$carrier)=split(" ",$dataLine[1]);
	}
	return $carrier;
}
 |