Thursday, June 17, 2010

What I did with Perl

Perl

What all features of Perl have I used?

\t Open
è Mutt/sendmail – for sending mail
è DBI
è When u declare a variable with @ at the start, it is an array.
Within an array, you can assign values like C/C++ -
Arr[0] = 1; Arr[1] = 2;
è You declare a variable when it starts with $
è Foreach – is for iteration
è For loop is exactly same as C++
è When you want to use a particular feature of perl, you say ‘use DBI’ and then you can use it.
è The function definition starts with ‘sub
è Each line in perl ends with a ‘;’
è If you do $MODE = ; the script will wait for user’s input, and once input is provided, that value will be assigned to MODE variable.
è Split function of perl strings is same as strtoken of strings.
è Foreach can be used as below –
foreach my $val (@temp_raw_value)
è Two strings can be concatenated as –
$String = $str1.$str2
è ‘Else if’ is like this – ‘elsif’
è and && are similar to C/C++
è If in a ‘if’ block, you want to do string comparison – following are the operators –
Eq, ne, gt, lt etc. Eg - if($DAY eq "Mon")
è

How about DB connectivity?
DBI is used.
Following different DBI methods are available to use –
use DBI;
my $db= DBI->connect("dbi:Oracle:dw", "igor", "igortom")
die( $DBI::errstr . "\n" );;
my $sql = “some query”
my $sth = $db->prepare($sql);

th->execute();
my $RESULT;
$sth->bind_columns(undef, \$RESULT);
$sth->fetch();
$sth->finish();
$db->disconnect();
return $RESULT;

What goals I achieved using Perl?
The script took few parameters from user like start date and end date, and generate some monetory statistics for that duration. Internally the script fired sql queries and worked on the results to provide stats. Once the stat is available, the mail is composed from those stats, and sent to the DL.

Why Perl and why not shell?
Shell is shell specific
Perl is platform independent

How do I call C++/Java APIs from Perl and vice versa?

What is mod_perl?

Comparison (Sybase-Oracle, UNIX-LINUX, Perl-Python)

Why is sybase better than Oracle ?
Sybase is better : secure, cheap, faster, low maintenance, skilled. http://www.rocket99.com/sybase/syb_vs_ora.html
http://www.dba-oracle.com/oracle_news/news_sybase_vs_oracle_linux.htm
Sybase is 20% to 3000% faster than Oracle.

Why is Linux catching up more compared to other UNIX flavors?
Linux cheaper, more secure, fast response to security threats, kernel freely available, http://www.linuxquestions.org/linux/articles/Technical/UNIX_Vs_Linux
http://www.diffen.com/difference/Linux_vs_Unix

Perl Vs Python