Wednesday, January 30, 2008

DBI.pm utilities - It is just a ctrl-c & ctrl-v

BEGIN {
$DBI::VERSION = "1.59"; # ==> ALSO update the version in the pod text below!
}

=head1 NAME

DBI - Database independent interface for Perl

=head1 SYNOPSIS

use DBI;

@driver_names = DBI->available_drivers;
%drivers = DBI->installed_drivers;
@data_sources = DBI->data_sources($driver_name, \%attr);

$dbh = DBI->connect($data_source, $username, $auth, \%attr);

$rv = $dbh->do($statement);
$rv = $dbh->do($statement, \%attr);
$rv = $dbh->do($statement, \%attr, @bind_values);

$ary_ref = $dbh->selectall_arrayref($statement);
$hash_ref = $dbh->selectall_hashref($statement, $key_field);

$ary_ref = $dbh->selectcol_arrayref($statement);
$ary_ref = $dbh->selectcol_arrayref($statement, \%attr);

@row_ary = $dbh->selectrow_array($statement);
$ary_ref = $dbh->selectrow_arrayref($statement);
$hash_ref = $dbh->selectrow_hashref($statement);

$sth = $dbh->prepare($statement);
$sth = $dbh->prepare_cached($statement);

$rc = $sth->bind_param($p_num, $bind_value);
$rc = $sth->bind_param($p_num, $bind_value, $bind_type);
$rc = $sth->bind_param($p_num, $bind_value, \%attr);

$rv = $sth->execute;
$rv = $sth->execute(@bind_values);
$rv = $sth->execute_array(\%attr, ...);

$rc = $sth->bind_col($col_num, \$col_variable);
$rc = $sth->bind_columns(@list_of_refs_to_vars_to_bind);

@row_ary = $sth->fetchrow_array;
$ary_ref = $sth->fetchrow_arrayref;
$hash_ref = $sth->fetchrow_hashref;

$ary_ref = $sth->fetchall_arrayref;
$ary_ref = $sth->fetchall_arrayref( $slice, $max_rows );

$hash_ref = $sth->fetchall_hashref( $key_field );

$rv = $sth->rows;

$rc = $dbh->begin_work;
$rc = $dbh->commit;
$rc = $dbh->rollback;

$quoted_string = $dbh->quote($string);

$rc = $h->err;
$str = $h->errstr;
$rv = $h->state;

$rc = $dbh->disconnect;

Standard DBD in PERL installation - We can implement ours too.

DBD::Adabas
DBD::ADO
DBD::Amazon
DBD::AnyData
DBD::ASAny
DBD::Chart
DBD::CSV
DBD::DB2
DBD::DBMaker
DBD::DBM
DBD::EmpressNet
DBD::Empress
DBD::ExampleP
DBD::Excel
DBD::File
DBD::Fulcrum
DBD::Gofer
DBD::Google
DBD::Illustra
DBD::Informix4
DBD::Informix
DBD::Ingres
DBD::InterBase
DBD::iPod
DBD::JDBC
DBD::LDAP
DBD::Log
DBD::MaxDB
DBD::Mimer
DBD::Mock
DBD::monetdb
DBD::mSQL
DBD::Multiplex
DBD::Multi
DBD::mysqlPP
DBD::mysql
DBD::NullP
DBD::ODBC
DBD::Oracle
DBD::Ovrimos
DBD::PgLite
DBD::PgPP
DBD::PgSPI
DBD::Pg
DBD::pNET
DBD::PrimeBase
DBD::Proxy
DBD::QBase
DBD::RAM
DBD::RDFStore
DBD::Recall
DBD::Redbase
DBD::Salesforce
DBD::SearchServer
DBD::Solid
DBD::Sponge
DBD::Sprite
DBD::Sqlflex
DBD::SQLite2
DBD::SQLite
DBD::Sybase
DBD::TemplateSS
DBD::Template
DBD::Teradata
DBD::TimesTen
DBD::TSM
DBD::Unify
DBD::WMI
DBD::WTSprite
DBD::XBase
DBD::Yaswi

Perl DBI Master Key Site

http://dbi.tiddlyspot.com/

This has most of the thing an experianced people using DBI need to know.

K-Shell programming

Very good site for ksh programming learning:

http://www.bolthole.com/solaris/ksh.html

Happy Learning.

Tuesday, January 29, 2008

Different compression techniques

http://en.wikipedia.org/wiki/Bzip2
http://en.wikipedia.org/wiki/Gunzip ( same as gzip)
http://en.wikipedia.org/wiki/Compress

Good read - gzip -

Good study article about gzip (GNU zip).

http://en.wikipedia.org/wiki/Gzip

Open Group Base Specifications (Owner of UNIX & POSIX)

Folks,

If you have any question regarding UNIX or UNIX like system aka POSIX standard and stuff, you can go to :

http://www.opengroup.org/

Friday, January 25, 2008

Brain Bench Perl 5.8 Certification

Folks,

I got certified in Perl 5.8 today and will be getting my certification in couple of days. It really has some good questions, worth taking a look at this exam.

-Deepak

Thursday, January 24, 2008

Perl Tricks

Quote and Quote-like Operators ------------------------------While we usually think of quotes as literal values, in Perl theyfunction as operators, providing various kinds of interpolating and pattern matching capabilities. Perl provides customary quote characters for these behaviors, but also provides a way for you to choose your quote character for any of them. In the following table, a {} represents any pair of delimiters you choose.

Customary Generic Meaning Interpolates
'' q{} Literal no
"" qq{} Literal yes
`` qx{} Command yes
* qw{} Word list no
// m{} Pattern match yes
* qr{} Pattern yes
* s{}{} Substitution yes
* tr{}{} Transliteration no (but see below
'<<'EOF here-doc yes

* * unless the delimiter is ''.

Perl Quiz Series - Part I

Perl Questions:

Generic Questions:
1. What is 'our' used for ?
e.g our($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS)
2. What is 'exists' function used for?
3. What is 'uc' function used for ?
4. What is 'ref' function used for ?
5. What is 'defined' function used for ?
6. What is 'map' function used for ?
7. What is 'reverse' function used for ?
8. What is ' qq qw ' used for ?
9. What is 'tr' function used for ?
10. What is 'tie' function used for ?
11. What is ' push & pop ' function used for ?
12. What is ' undef ' function used for ?
13. What is ' bless ' function used for ?
14. What is ' self ' function used for ?
15. What is ' __FILE__ ' variable used for ?
16. What is ' __LINE__ ' variable used for ?
17. What is ' $_ ' used for ?
18. What is ' @_ ' used for ?
19. What is ' $$ ' used for ?
20. What is ' shift ' function used for ?
21. What is ' unless ' function used for ?
22. What is ' self ' function used for ?
23. What is ' untie ' function used for ?
24. What is 'split' function used for ?
25. What is 'splice' function used for ?
26. What is 'sort' function used for ?
27. What is 'keys' function used for ?
28. What is 'values' function used for ?
29. How to dereference a array reference $ref_a ? ( @$ref_a )
30. How to dereference a hash reference $ref_h ? ( %$ref_h )
31. How to dereference a scalar reference $ref_s ? ( $$ref_s )
32. What is difference between 'for & foreach' loop ?
33. What is 'while' function used for ?
34. What is 'last' function used for ?
35. What is 'exit' function used for ?
36. What is difference between 'die & warn' ?
37. What is 'eval' function used for ?
38. What is '$@' variable used for ?
39. What is 'Here document' ?
40. What is difference between 'exec & system' function?
41. How to set environment variable in perl ? ( $ENV{xx} )
42. What is ' $ ' (dollar pipe) used for ?
43. What is 'shebang'? ( #! ) --> first line of perl code
44. Can we use ' -w ' switch on first line OR 'use warnings' module alternatively ?
45. What is the difference between 'chomp & chop'?
46. How to invoke a unix shell command inside a perl script ? ( `ls -l` )
47. What is the difference between 'use & require' ?
48. What is '@ARGV' used for ? (Number of arguments)
49. What is ' . ' ( dot operator ) used for ?

Wednesday, January 23, 2008

Use google search engine from command line.

#!/usr/bin/perl -w

my $browser = "/usr/bin/mozilla-firefox";
exec $browser, "http://www.google.com/advanced_search" unless @ARGV;

for ( @ARGV )
{
s/.*/%22$&%22/ if y/ /+/; $s .= $s?"+$_":"$_";
}

exec $browser, "http://www.google.com/search?num=30&hl=en&as_qdr=all&q=$s&btnG=Google+Search"

Friday, January 11, 2008

can I use $match within regex , sun as / $match ../

Building a pattern at run-time by interpolating a variable into a pattern. Yes, you can interpolate a variable such as $match into a pattern; you'll generally want the qr// operator to quote the pieces you use to make $match.

http://perldoc.perl.org/perlop.html#Regexp-Quote-Like-Operators