Thursday, May 14, 2009
Best practices for a high performance Perl program
http://makepp.sourceforge.net/1.50/perl_performance.html
Wednesday, March 4, 2009
Validating data types in PERL
Since perl data types are very typeless and depends upon where they are used. There are some situations, when this design is awkward.
To validate data types,
Data::Types module can be installed and used.
However if you dont want to install, here are few quickies:
- To Check
% An Integer, Use regex /^[+-]?\d+$/ and ofcourse, not matched ones are non-intger
% A Decimal, /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/
% Whole number, /^\d+$/
% Float number, /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
%
To validate data types,
Data::Types module can be installed and used.
However if you dont want to install, here are few quickies:
- To Check
% An Integer, Use regex /^[+-]?\d+$/ and ofcourse, not matched ones are non-intger
% A Decimal, /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/
% Whole number, /^\d+$/
% Float number, /^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/
%
Wednesday, February 25, 2009
Python Advance books
A Good link for description of these books.
http://wiki.python.org/moin/AdvancedBooks
http://wiki.python.org/moin/AdvancedBooks
Monday, November 24, 2008
How to group UNIX Solaris, Linux commands
Simply group them in a small bracket and separate them by semi colon (;)
123-bash: (ls -1;pwd;cd /tmp/curl)
It will list the files in CWD first, print the directory you are in, cd to /tmp/curl
123-bash: (ls -1;pwd;cd /tmp/curl)
It will list the files in CWD first, print the directory you are in, cd to /tmp/curl
Tuesday, November 18, 2008
How to get user input in PERL
It's simple -
- The angle bracket operator to read from STDIN (see I/O operators in perlop)
- If entering 'Y' or 'N' - make sure to use 'chomp' to cut the new line character.
- @ARGV - the array that holds parameters from the command line (see perlvar)
- Getopt::Long or Getopt::Std - for more powerful handling of command line arguments
- uc - to uppercase an expression
- ucfirst - to uppercase the first letter of an expression
Later in your code, you can compare by using 'eq' or 'ne' or '==' or '!=' or
pattern matching =~ m///, thingy to move on to do what you want.....
- The angle bracket operator to read from STDIN (see I/O operators in perlop)
- If entering 'Y' or 'N' - make sure to use 'chomp' to cut the new line character.
- @ARGV - the array that holds parameters from the command line (see perlvar)
- Getopt::Long or Getopt::Std - for more powerful handling of command line arguments
- uc - to uppercase an expression
- ucfirst - to uppercase the first letter of an expression
Later in your code, you can compare by using 'eq' or 'ne' or '==' or '!=' or
pattern matching =~ m///, thingy to move on to do what you want.....
Friday, November 14, 2008
Solaris Kernel Modules operations
Kernel Modules:
---------------
modinfo : prints out information on all currently loaded kernel modules.
modload : loads kernel modules.
modunload : unloads kernel modules.
forceload : in the /etc/system file loads a module at boot time.
---------------
modinfo : prints out information on all currently loaded kernel modules.
modload : loads kernel modules.
modunload : unloads kernel modules.
forceload : in the /etc/system file loads a module at boot time.
Monday, November 10, 2008
Passing a DB handler to an user defined function
It is pretty simply. Pass it like an ordinary variable.
Example here:
#!/opt/local/bin/perl
use db_connect;
use warnings;
use strict;
# More efficient than ./test_connection.pl because $0 makes only one DB connection
my $obj = db_connect->new();
my $db = $obj->connect_qora007_mir("qora007_mir");
print " \n";
&checkConnectionMIR_qora007($db);
&checkConnectionCIR_qora007($db);
print " \n";
$db->disconnect();
sub checkConnectionMIR_qora007($)
{
my $dbh = shift;
my $sql;
my $sth;
my $str;
my @row;
$sql = "select sysdate from dual";
$sth = $dbh->prepare($sql);
$sth->execute;
while((@row) = $sth->fetchrow_array())
{
$str = join(" " , map {defined $_ ? $_ : "(null)"} @row);
print "INSTANCE: $str\n";
}
Example here:
#!/opt/local/bin/perl
use db_connect;
use warnings;
use strict;
# More efficient than ./test_connection.pl because $0 makes only one DB connection
my $obj = db_connect->new();
my $db = $obj->connect_qora007_mir("qora007_mir");
print " \n";
&checkConnectionMIR_qora007($db);
&checkConnectionCIR_qora007($db);
print " \n";
$db->disconnect();
sub checkConnectionMIR_qora007($)
{
my $dbh = shift;
my $sql;
my $sth;
my $str;
my @row;
$sql = "select sysdate from dual";
$sth = $dbh->prepare($sql);
$sth->execute;
while((@row) = $sth->fetchrow_array())
{
$str = join(" " , map {defined $_ ? $_ : "(null)"} @row);
print "INSTANCE: $str\n";
}
Subscribe to:
Posts (Atom)