Wednesday, 18 January 2012

Unix Perl - Some useful commands.

Here's some useful quick tips in Unix Perl.

1) To see Perl DBI installed and its version  :
perl -e 'use DBI; print $DBI::VERSION,"\n";'
2) To see Perl DBD installed and its version

perl -e 'use DBD::Oracle; print $DBD::Oracle::VERSION,"\n";'

3) Just to Connect to Oracle :

use strict;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:fs1pa_fs1p','<uname>','<passwd>',)|| die "DB conn not made: $DBI::errstr";
$dbh->disconnect;

4) Connect to Oracle and simple Query
use strict;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:fs1pa_fs1p','<uname>','<passwd>',)|| die "DB conn not made: $DBI::errstr";
my $sql = qq{ SELECT TNAME,TABTYPE FROM TAB };
my $sth = $dbh->prepare($sql);
$sth->execute();
my($tname,$tabtype);
$sth->bind_columns(undef, \$tname, \$tabtype);
print "List of Table:\n\n";
while ($sth->fetch() ) {
        print "Object :$tname, Type :$tabtype\n";
}
$sth->finish();
$dbh->disconnect;


5) insert line numbers in a file 
perl -pi -e'$_ = sprintf "%04d %s", $. $_' filename

6) change pattern 'print' to 'printf' and change in same file
perl -e 's/print/printf/g' -p -i  file_name

7) Print no.of lines
perl -le 'open FILE, "file.txt";@_=<FILE>; print $.'

8) just lines 4 to 6
perl -ne 'print if 4 .. 6' file.txt
perl -ne 'print if 4..6' file.txt

 9) Print first column values from line 4 to 6
 perl -F'\|' -lane 'print $F[0] if 4..6' file.txt

10) Avoids the blank lines and print only the lines with contents
perl -ne 'print unless /^$/../^$/' test.txt

 11) Prints only the matching words
perl -lne '/Mukundan/ and print $&' file.txt


12) Prints the entire line
perl -lne '/Mukundan/ and print $_' file.txt
 

13) Get all the PACKAGE objects from oracle
use strict;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:fs1pa_fs1p','<user>','<passwd>',)|| die "DB conn not made: $DBI::errstr";
my $sql = qq{ SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE=? };
my $sth = $dbh->prepare($sql);
$sth->execute("PACKAGE");
my($oname);
$sth->bind_columns(undef, \$oname);
print "List of Packages:\n\n";
 while ($sth->fetch() ) {
        print "Packages :$oname\n";
}
 $sth->finish();
$dbh->disconnect;

Tuesday, 17 January 2012

Review on BSNL Wimax in Kerala

I took BSNL WiMax ( Mobile WiMAX 802.16e) connection in September 2010 from Panampilly Nagar , Ernakulam. 

Here's the schematic diagram of the connection :

I opted for outdoor CPE , since with indoor CPE was not getting good signals when BSNL folks did the feasibility study.



They posioned the CPE towards the BSNL tower.  Once you connect the CPE to your PC using the LAN cable , you can enter the account credentials in the modem status page ( 192.168.1.1). Once after successful authentication , the status page will look like this



You will get a good connection if the RSSI value between -50dBm & -65 dBm and CINR value of 18 to 25. With above setup I was getting almost 2 Mbps download speed with torrents.

I am very happy with the Wimax xonnection. Moreover you can transfer the connection anywhere in Kerala ( yeah.. Roaming allowed ).