Perl beginner – install and run hello world, MySQL test

I am seasoned PHP programmer, been around ten years I am coding on PHP. Although I learn and tried many different programming languages, I always scare to give a try to Perl. I was in impression that Perl is difficult language so never get confident to try it, or never can arrange time for it. But, today as I was working on Asterisk for VoIP system, there’s was no choice left, but Perl.

I gave first try today in Ubuntu. It wasn’t that bad as I heard. Actually I was wrong about Perl, it was proved.

Below is how, I tried first hello world and first database application

Install Perl

  1. $ sudo apt-get install perl

 

Don’t worry, if Perl is already installed, it do nothing. If you have Ubuntu server edition, Perl is already there.

 

Create directory called perl_test. Create perl_test.pl file and save following content.

  1. #!/usr/bin/perl
  2. #simple perl program to print the user input
  3. print ("Hello world! test goes this\n");
  4. $inputline=<stdin>;
  5. print ($inputline);

 

Save file named as perl_test.pl and run following command.

  1. $ sudo chmod +x perl_test.pl
  2. $ ./perl_test.pl

 

Database Test:
Create perl_db.pl file and save following content.

  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use DBI;
  5.  
  6. my $username='test';
  7. my $pass='test';
  8. my $db='test';
  9. my $dbh = DBI->connect( "dbi:mysql:$db", $username, $pass, { 'PrintError' => 1, 'RaiseError' => 1 } );
  10. my $sql='select * from test';
  11. my $sql_handle=$dbh->prepare($sql);
  12. $sql_handle->execute();
  13. my @data;
  14. while (@data=$sql_handle->fetchrow_array()) {
  15. print join("\n",@data)
  16. }

 

  1. $ sudo chmod +x perl_db.pl
  2. $ sudo ./perl_db.pl

 

Make sure user test with password test and database test exits. And it has test table.

 
Haurry!!!

Asterisk – Custom Telephony Solutions

Couple months, I had researched Asterisk, a Telephony Solutions.

What is Asterisk? Asterisk is *, means everything. It may sound like lame definition here, but trust me you gonna believe it. I am not going to refer you to two handful links www.asterisk.org and Wikipedia entry. So, Asterisk supports all most all Telephony Protocols and it’s framework and gives you power to customize everything, so as it is *.

Scenario, you want to run call center and you have telemarketers around world – some like to go vacation in Palm Island and work from sunny beach with wireless connection, some want to work from home while feeding their baby and some want to work while traveling in odd hours. Can you give that level of flexibility, may be no, may be YES. On top of that, as boss you still want to be sure that everyone is working and be able to monitor them.

Here’s how Asterisk can help, whole days I am was designing solution over it (tough assignment, yet interesting). You need telephony server (IP PBX) and SIP client. You can configure it to interoperate verity of network like VoIP or PSTN. I would describe general concept rather not technical aspect. For technical how-tos, may be I post other blogs in coming days.

Server: Download Asterisk and install, it’s very easy. Get source, configure, make and make install! Connect PSTN line with suitable hardware (Digium provide sophisticated hardwares). You done, it is your IP PBX or telephony server.

Configure Extensions: Extensions! yes, they are PBX extensions. You can assign extension number and you can set authentication. Usually you can tap each telemarketer with extension number. So you can monitor each of them, log their telephone record (known as CDR).

Configure Dialplan: Dialplan is kind of rule how do you want handle inbound and outbound call. For example, you want to redirect call to voicemail if not answered in 2 minute, or you want to play music/instruction after 5 second.

SIP clients: SIP clients are usually Softphones. Your telemarketer has to use softphone to make call. SIP client is extension, you can say, as each SIP client is allocated a extension number. So, each of SIP client connects to IP PBX server and make call. While making call, SIP client will be authenticated. Authentication credential will be as of defined while configuring extension.

So, you see how you can keep track hundreds of telemarketers call. Give one extension to each telemarketer and give them username and password as set in extension. When a telemarketer makes from softphone, he has to provide user name and password. In this scenario, I give you my own kind of mathematic formula, SIP client=extension number=telemarketer.

This is just great!!!