Chapter 1. Perl Meets Oracle

Perl is the world’s number one solution for transforming and gluing data together, and Oracle is the world’s number one solution for storing that data. In this book we’ll explore the interface between two of the finest American inventions since baseball and pretzels. We’re going to grab that Oracle data, we’re going to flip that Oracle data, and we’re going to munge that Oracle data. And we’re going to do it all in Perl!

The goal of this book is to explore the frontier connecting the Perl and Oracle worlds, having as much fun along the way as possible. There are many routes through this largely unexplored territory, and one we think is particularly important is the one focused on Oracle database administration. We are Oracle DBAs ourselves and we know the frustrations the job can bring. We’ve found Perl an enormous help to us in performing administrative tasks — both routine ones, like adding new users to the database, and more complex ones, like monitoring database connectivity in real time and tracking down database performance problems by comparing SQL execution plans. We want to share the information we’ve acquired over the years about Perl and its many Oracle applications. We also want to give you access to our own Oracle database administration scripts, which we’ve packaged up in the Perl Database Administration (PDBA) Toolkit described in this book and freely available on the O’Reilly web site.

This chapter sets the scene by introducing you to Perl and how it connects to Oracle. We’ll look at the following:

Perl’s origins and advantages

We’ll take a look at where Perl came from and what makes it such a popular and powerful language.

Perl/Oracle architecture

We’ll see how Perl connects to the Oracle database via the Perl DBI module, the DBD::Oracle program, and Oracle’s own OCI product. These modules interact to allow Perl programs access to Oracle databases.

Perl for Oracle DBAs

We’ll discuss why Perl is a particularly appropriate language for Oracle DBAs to learn and use.

We’ll also provide a list of additional Perl resources.

What is Perl?

Perl is a wonderful language with a rich history and culture. Many books have been written about its capabilities and roots. In this book we’ll be focusing on how Perl and Oracle work together, and we’ll only skim the surface of Perl’s overall capabilities, giving you just enough detail so you’ll appreciate what Perl can do for you.

In a nutshell, Perl is a freely available interpreted scripting language that combines the best capabilities of a variety of other languages. Despite borrowing other language capabilities, the whole of Perl is far greater than the sum of its parts. Perl was designed especially to be:

  • Extremely fast, in order to be useful when scanning through large files

  • Especially good at text handling, because data comes in many different forms and Perl has to handle them all

  • Extensible, in order for Perl to expand users’ horizons, not restrict them

A tutorial for basic Perl is outside the scope of this book. Fortunately, there are many excellent web sites and books containing the information you need to get going. We’ve collected references to what we consider to be the best Perl books and online documentation in Section 1.4 at the end of this chapter. The appendixes provide quick references to different aspects of Perl’s capabilities. For online information, check out the main Perl portals at:

http://www.perl.com
http://www.perl.org
http://www.activestate.com (for Win32)

Before we get into the details of how Perl and Oracle interact, let’s take a step back to look at where Perl came from.

The Origins of Perl

Larry Wall created Perl back in 1987 with the goal of making “the easy things easy and the hard things possible” — originally just for himself, but ultimately for a whole generation of developers. Larry had been working on a complex system and had been trying to get Unix’s awk utility to do his bidding. He finally gave up on it and under the auspices of a secret project for the National Security Agency known as the “Blacker,” he decided to create a new language by raiding a primeval soup of technologies and splicing together the genetic structures of awk, sed, sh and C, as well as csh, Pascal, and BASIC. The first release of Perl, Perl 1.0, arrived after a nine-month gestation period.

Perl was unlike any other computer language that had come before it, and this sea change was partially reflected in the name. The original name, “Pearl,” stood for “Practical Extraction And Report Language,” but in the spirit of this compact language, Larry wanted to save typing that extra fifth character. The name quickly morphed into Perl, which by now also stood for “Pathologically Eclectic Rubbish Lister.” This self-irreverence further distinguished the language and gave it a certain counter-culture cachet.

Perhaps the most accurate summary of what Perl is best for can be found in the README file written by its author for Perl Version 1.0:

Perl is a interpreted language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports based on that information. It’s also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). It combines (in the author’s opinion, anyway) some of the best features of C, sed, awk, and sh, so people familiar with those languages should have little difficulty with it. (Language historians will also note some vestiges of csh, Pascal, and even BASIC|PLUS.) Expression syntax corresponds quite closely to C expression syntax. If you have a problem that would ordinarily use sed or awk or sh, but it exceeds their capabilities or must run a little faster, and you don’t want to write the silly thing in C, then perl may be for you. There are also translators to turn your sed and awk scripts into perl scripts. OK, enough hype.

The Unix world embraced the Perl language, and the fast-growing Perl development community gradually built their favorite language into the world’s supreme text-processing engine. Over the next few years, Perl grew ever more powerful. Perl’s regular expression handling was enhanced, the ability to handle binary files was added to the language, and the three main variable types were honed and sculpted. Soon the Perl Artistic License was adopted, and with the publication of the first edition of Programming Perl, the definitive guide to the language, the camel became the Perl trademark.[3]

Perl has become hugely popular, largely because of its extremely fast text processing and its ability to glue difficult things together with ease. With the explosion of the interactive Internet in the 1990s, Perl found itself superbly pre-adapted to become the new tool of an Internet generation. It glued those trillions of text packets into one big global village! And as the World Wide Web burst on the scene, Perl continued to evolve, emerging as the premier language for developing web applications. Perl 4 brought the release of modules allowing Perl to interact with Oracle (and other) databases. The current version of Perl, Perl 5, contains long-sought object-oriented features.

Perl on Win32

Although Perl’s origins were in the Unix world, it was ported to Windows back in 1995 by Dick Hardt and Hip Communications, the forerunners of ActiveState. Windows NT administrators then discovered a whole new world of functionality via the Win32 modules supplied by ActiveState, and Perl became their dominant scripting language. Perl was a lifesaver for busy administrators performing large NT system updates. (Adding 100 users to a system via the repetitive and arthritic point-and-click method really is no fun!)

Win32 Perl became so popular that there was some danger that the Unix and Windows versions would diverge. But Larry Wall was not about to let this happen. Those not familiar with Perl may wonder why it matters. What difference would it make if the Unix and Win32 Perls were different? In fact, it is this hard-won unity that gives Perl its power. You can write a single script on one operating system, and as long as you don’t use native methods, you can run it unchanged on every other kind of machine, from Linux to Windows NT to Solaris and back again. That is a huge advantage in our multiplatform, networked computing world.

CPAN (the Comprehensive Perl Archive Network)

Over the years, an enthusiastic and partisan army of Perl volunteers has extended Perl in a myriad of ways. CPAN (the Comprehensive Perl Archive Network), an online repository of Perl core files, documentation, and contributed modules, has become a model for an open source development community. Check out:

http://www.cpan.org

Literally thousands of Perl modules are now available on CPAN, providing virtually any application you can imagine — and many you haven’t yet imagined. Just about every Perl module we describe in this book, from core modules like Perl and Perl DBI themselves to Oracle-specific database administration scripts like OraExplain and Orac, can be downloaded from CPAN.

New Perl modules go through an evolutionary process that begins with an individual developer’s code, which he or she posts to CPAN. As others learn about the new module and start downloading and testing it, and relying upon it, it becomes more and more acceptable. If it’s good enough, and if enough people and products rely upon it, the Perl gods ultimately might decide to include the new module in the next general Perl distribution.

Perl and the corporate world

When Java, Microsoft’s Active Server Pages (ASP), and similar corporate tools came along, many people assumed that they would sweep the inelegant Perl away. However, this hasn’t come to pass. Instead, Perl has grown exponentially both in market share and stature, especially since its 1994 Perl 5 adoption of reference technology, which greatly increased its scope in terms of both extensibility and object orientation. Tim Bunce’s Perl DBI module, built on the object-oriented base, gave Perl the ability to interface with Oracle and other databases. The fact that Perl can now dynamically glue the Internet to the database has greatly increased corporate acceptance of the language.

The Perl Advantage

There are nearly as many reasons why people choose to use Perl as there are people who use Perl. Aside from the language’s specific capabilities, we think there are a few key reasons for Perl’s awesome acceptance among programmers and nonprogrammers alike:

Practicality

Unlike some languages that have developed within the ivory towers of computer science departments, Perl is a practical language. It is unbound by dogma and driven by day-to-day practicalities. With its flexible syntax, it gives users enormous freedom to do what they want to do.

Bandwidth

Perl is one of the most concise languages around. In ten lines of Perl code, you can achieve more than is possible in any other language. Disciplined use of Perl can thus reduce program maintenance costs (because there’s less to maintain) and aid clarity (because there’s less code to try to understand).

Range

Literally thousands of Perl modules are available for download from CPAN, covering virtually every computing requirement imaginable. The abundance of prebuilt code modules makes Perl the number one choice for anyone with a wide range of programming needs — and that description fits most Oracle DBAs.

We believe that Perl’s popularity is based to a large extent on the fact that it has resisted the temptation to try to become the most elegant language of its time. A linguist by training, Larry Wall took many lessons from the development of real-world natural human languages, and blended the necessary messiness of those languages into his evolving design for Perl. In the following sections we’ll look at how the English language itself offers some important Perl analogies.

Flat learning curve

Although natural languages such as English are difficult and messy, even a baby can learn them. The messiness of such languages aids learning, develops expression, and allows the human mind to map complex real-world problems onto the symbolic logic of complex real-world languages. Perl tries to follow this pattern — it’s very intentionally designed for humans rather than computers. You need only a little Perl to get going, just as a baby needs only a little language to ask for a chocolate ice cream. Indeed most of the fun of Perl is that you never stop learning about its new elements. This characteristic of Perl contrasts with some other languages where you have to learn virtually the entire shooting match before you can do the simplest thing, such as print:

"Hello World! :-)"

It also means that it’s okay to know only parts of the whole language — every Perl programmer is on the same flat learning curve as every other Perl programmer, merely at a different position.

Expression

Perl is optimized for expressive power, rather than ease of operation. Once you’ve learned an element of Perl, such as the structure of hashes (described in Appendix A), you can use this knowledge in many different ways to achieve many different ends. Again, this is similar to English, in which you can learn a rhetorical debating technique and then employ it in many different ways to get what you want.

There’s more than one way to do it (TMTOWTDI)

In many computer languages, there’s often a single acceptable way to do a certain thing — for example, communicate with a distant server. Perl is different. So is English. In real life, when you introduce yourself to other people, there are many different ways to successfully perform this occasionally tricky verbal task. It’s the same in Perl. What counts is what works best for you, not some rigid adherence to a strictly enforced protocol. As with formal introductions, of course, there are certain conventions that most people use. There is peer pressure even among Perl programmers. But Perl itself doesn’t care; if you want to do something different, you are free to do so.

Flexibility

English is a successful language mainly because it looks forward into the future, rather than backward towards its origins. It’s built up from Latin, Greek, French, Anglo-Saxon, and many other elements. And if it needs to borrow the word “veranda” from the Portuguese in order to describe a covered porch, it just goes right ahead without worrying about whether doing so breaks some rule. Perl is the same: if it sees a great idea in Java, it just goes right ahead and borrows it, slipping it in so the join is invisible. Eventually, if it’s a successful graft, even Java programmers may come to think that the idea originally came from Perl. It is this continuous evolution that transforms Perl from the ordinary into the extraordinary.

Ambiguity

English is also successful because it’s so good at handling ambiguity. Although there are few cases, genders, or definitive word endings in the English language, local ambiguities are quickly resolved by the juxtaposition of certain other words, conventions, and punctuation. Perl is the same: some pieces of isolated code can be quite ambiguous, but the ambiguity is quickly resolved in the context of its word order, punctuation, and relationship to other code fragments. There are even pronouns in Perl, such as $_ and @_ for “it” and “they”!

Acceptance of the real world

In a pure computer language world, you could visit the local cinema in an infinite number of ways; for example, you could float up to 10,000 feet, disappear, and then rematerialize in your favorite seat to watch The Lord of the Rings. But the fact is that you’d most often walk or drive there. Similarly, Perl recognizes that most people tend to want to do things in familiar ways (e.g., opening a file, processing the lines in it, and then closing the file). So Perl will typically assume that you’ll be following a natural order unless you tell it explicitly that you won’t be.

Simplicity

Lawyers have taken the once straightforward English language and twisted it into the most tortuous logic the human mind could devise — unfortunately, this is the route most often taken by other computer languages. They start simply enough, but develop a rigid straitjacket of theoretical perfection before drowning in a bog of complexity. You’ll be pleased to hear that Perl is much friendlier. There is no ideology that must be obeyed. A country run by Perl programmers would be a really cool place to live!

Cooperation and divergence

Natural languages have evolved with the involvement of different people over a long period of time — indeed, they continue to evolve. They’re also continuously diverging into separate dialects and even other languages. Perl too began as an amalgam of different ideas, shepherded together by Larry Wall. It has since continued as a cooperative effort, with many contributing voices. The eventual creation of Perl 6 will be one vast community effort (something we hope you’ll be part of).

But language fragmentation has been an ongoing problem for Perl. The solution has been a continuous release program over the last decade that has accommodated divergent tendencies. The CPAN architecture also offers a outlet for those with independent voices. The threatened Win32 divergence we discussed earlier in the Section 1.1.1.1 could have had a dramatic impact on the unity of Perl — and all that implies in terms of portability and extensibility. Thankfully, as we described earlier, that threat came to a happy conclusion. And it’s still true that if you write a Perl script on one operating system, then as long as you haven’t used native methods and system commands, the script can be copied to any other machine and will work there identically, regardless of operating system.

The Perl/Oracle Architecture

How do Oracle DBAs, developers, and users take advantage of everything that Perl has to offer? The architecture illustrated in the figures in the following sections show how the various Perl and Oracle modules fit together to make the Perl/Oracle connection clean and efficient. In the following sections we’ll take a look at the main components of this architecture:

  • Perl DBI

  • DBD::Oracle

  • OCI

Perl DBI and DBD::Oracle are Perl modules available from CPAN. OCI is an Oracle Corporation product that comes with all versions of the Oracle database.

Perl DBI and DBD::Oracle

Perl DBI is a generic application programming interface (API). It is similar in concept to ODBC (Oracle DataBase Connectivity) and JDBC (Java DataBase Connectivity), but it has a Perl-based object-oriented architecture. Perl DBI’s object-oriented architecture allows it to have a single routing point to many different databases (shown in Figure 1-1), each via a database-specific driver. Oracle uses the DBD::Oracle driver, another Perl module that provides the actual communication to the low-level OCI code. It is OCI that makes the final connection to the Oracle database.

Perl DBI can interface to many databases

Figure 1-1. Perl DBI can interface to many databases

The beauty of Perl DBI is you can forget the details of the necessary connections beneath its simple API calls. The DBI package glides serenely over the surface of our databases, while the driver module, DBD::Oracle, does all the hard paddling beneath the surface.

Figure 1-2 shows how all the modules fit together on the Perl and Oracle sides.

The Perl/Oracle architecture

Figure 1-2. The Perl/Oracle architecture

The origins of Perl DBI

The origins of Perl DBI date back more than a decade. Way back in 1991, an Oracle DBA, Kevin Stock, created a database connection program called OraPerl that was released for Perl 4. Over time, similar Perl 4 programs appeared, such as Michael Peppler’s Sybperl, designed for communication with the Sybase database. In a parallel development, starting around September of 1992, a Perl-based group was working on a specification for DBPerl, a database-independent specification for Perl 4. Within two years they were just ready to start implementing DBPerl when Larry Wall started releasing the alpha version of the object-oriented Perl 5. Taking advantage of both Perl 5 and the earlier Call Level Interface (CLI) work from the SQL Access Group, the DBPerl team relaid the foundations of Perl DBI within an object-oriented framework, creating this new architecture in a similar form to that employed by the familiar API of ODBC. Meanwhile, Tim Bunce wrote an emulation layer for OraPerl Version 2.4 that let people easily move their legacy Perl 4 OraPerl scripts over to Perl 5 and Perl DBI.

With the new DBI architecture, you could now transparently employ just one Perl module to connect to every type of database, as long as you had the right driver. Fortunately for Oracle DBAs, Tim Bunce, the main creator of Perl DBI, is also the main creator of DBD::Oracle, which automatically keeps Oracle on the cutting edge of Perl DBI’s development schedule.

The Perl DBI API

We won’t try to describe all of the capabilities of Perl DBI here, but Table 1-1 provides a summary of the main calls (e.g., DBI class methods) to OCI. For additional background information about Perl DBI, see Appendix B. And for much more information, consult the references listed under Section 1.4.2 at the end of this chapter.

Table 1-1. Main Perl DBI functions

DBI function

Description

available_drivers( )

Lists all of the available DBD drivers including DBD::Oracle

data_sources( )

Lists all of the databases available to DBD::Oracle

connect( )

Establishes an Oracle database connection

disconnect( )

Disconnects a login session from Oracle

err( )

Returns the relevant Oracle error code

errstr( )

Supplies an associated Oracle error message

prepare( )

Prepares a SQL statement for execution

execute( )

Executes a prepared statement

do( )

Prepares and executes a single SQL statement all together

bind_param( )

Binds a value to a prepared statement

commit( )

Commits a transaction

rollback( )

Rolls back a transaction

table_info( )

Fetches metadata information from a table

fetchrow_arrayref( )

Fetches a row of data into a referenced array

fetchrow_array( )

Fetches a row of data into an array

selectrow_array( )

Executes prepare( ), execute( ) and fetchrow_array( ) all in one call

The Oracle Call Interface

As we’ve said, Oracle Corporation’s Oracle Call Interface (OCI) is the component in the Perl/Oracle architecture that makes the final connection to the Oracle database servers. This C-based API provides a comprehensive library used to connect into Oracle from the external world. Use of OCI lets your Perl programs take advantage of the following OCI capabilities:

  • High performance

  • Security features, including user authentication

  • Scalability

  • N-tiered authentication

  • Full and dynamic access to Oracle objects

  • User session handles

  • Multi-threaded capabilities

  • Support for accessing special Oracle datatypes such as LOBs (large objects)

  • Transactions

  • Dynamic connection and session management

  • Asynchronous event notification

  • Access to other databases

  • Full character set support

For more about OCI, see Chapter 7, where we describe Oracle::OCI, a new Perl module that provides an even closer interface between Perl and Oracle. You can get complete information about OCI at Oracle Corporation’s http://technet.oracle.com pages; in particular, see http://technet.oracle.com/tech/oci/.

In Table 1-2 we list the main OCI functions to give you a sense of the kinds of Oracle operations you can invoke from your Perl programs.

Table 1-2. Main OCI functions

OCI function

Description

OCIAttrSet( )

Sets handle attributes

OCIAttrGet( )

Gets attributes from a handle

OCIBindByName( )

Links variables to a SQL statement placeholder by name

OCIBindByPos( )

Links variables to a SQL statement placeholder by position

OCIDefineByPos( )

Links a typed select-list item with the output data buffer

OCIDescribeAny( )

Describes schema objects

OCIDescriptorAlloc( )

Allocates storage for descriptors and LOB locators

OCIDescriptorFree( )

Releases the resources taken by descriptors

OCIEnvInit( )

Allocates the initial OCI environment handle

OCIErrorGet( )

Returns a buffered error message

OCIHandleAlloc( )

Points to an allocated handle

OCIHandleFree( )

Explicitly releases a memory handle and its resources

OCIInitialize( )

Initializes the environment for OCI processes

OCILobRead( )

Reads specified LOB and FILE portions into a buffer

OCILobWrite( )

Writes a specified buffer into a LOB

OCILogoff( )

Ends a login session

OCILogon( )

Logs into the OCI session

OCIParamGet( )

Gets the descriptor of a parameter attached to a statement handle

OCIParamSet( )

Puts the object retrieval descriptor into an object retrieval handle

OCIServerAttach( )

Creates the pathway to a data source

OCIServerDetach( )

Detaches from a data source

OCISessionBegin( )

Begins a user session for a given server

OCISessionEnd( )

Ends a user session

OCIStmtExecute( )

Sends an application request to the server

OCIStmtFetch( )

Fetches data rows from previous queries

OCIStmtPrepare( )

Prepares a SQL statement for later execution

OCITransCommit( )

Commits a nominated transaction

At the most basic level, virtually all outside programs — from web applications to standalone GUI applications — interact with Oracle through this OCI program layer. Fortunately, the OCI libraries are automatically available in every Oracle database installation, so no special installation process is required. You’ll generally discover the appropriate files under the $ORACLE_HOME/lib and $ORACLE_HOME/include directories, on Unix systems, and under %ORACLE_HOME%\lib and %ORACLE_HOME%\include on Win32.

Perl for Oracle DBAs

Perl has become an increasingly popular tool for Oracle DBAs who need a quick way of handling the 101 different jobs a DBA is expected to do every day. Perl is operating system-independent, powerful, flexible, remarkably quick to code, and extremely fast in execution. These capabilities are especially important if you are working in a rapidly changing environment where one day you might be populating a data warehouse from a difficult data source, and the next you might be generating all of the information for a dynamic web application — and the whole time you’re performing all of your usual administrative tasks. That certainly describes the diverse world of an Oracle DBA!

Of course, the focus of any Oracle site’s business is data. And from the start, Perl was designed to be a data-processing engine, perhaps the finest and quickest in the world. It can find data, clean data, parse data, substitute data, print data, eat data, and spit data out from the other end in the exact format you require. It can do all of this with text data, binary data, and network data.

There are a variety of ways that Oracle DBAs can combine the power of Perl and Oracle. We describe four main paths in this book; the following list provides a road map:

Existing modules and applications

All kinds of excellent Perl modules and complete open source applications are freely available for Oracle DBAs to use. The chapters in Part II of this book describe the Perl/Oracle applications that we consider the best of the bunch; these are listed in Table 1-3 and fall into several categories:

Perl GUI applications

In Chapter 3, we describe Perl/Tk, Perl’s own tookit for developing graphical user interfaces, along with a variety of graphical Oracle applications and helper modules: OraExplain, StatsView, Orac, DDL::Oracle, SchemaDiff, Senora, DBD::Chart, SchemaView-Plus, as well as some Perl GUI integrated development environments (IDEs) and debuggers.

Perl web-based applications

In Chapter 4, we discuss the use of Apache with Perl and Oracle and describe two particular applications, Oracletool and Karma. In Chapter 5 we show how using the Apache mod_perl module can greatly improve the performance of Perl web-based scripts. And in Chapter 6, we discuss two embedded Perl web scripting applications, Embperl and Mason.

Connectivity tools

In Chapter 2, we describe how to install Perl DBI and DBD::Oracle to allow your Perl programs to interact with Oracle databases with great ease and efficiency. Later chapters describe some additional connectivity tools. In Chapter 7 we describe the new Oracle::OCI module that provides higher performance and a true one-to-one mapping with functions of the Oracle Call Interface. In Chapter 8, we describe Perl’s extproc_perl, Oracle’s EXTPROC, and the other modules that allow Perl to be essentially embedded into Oracle’s own PL/SQL language.

Database administration scripts

Just about every Oracle DBA has his or her own set of scripts they’ve written to make their daily lives easier. Many of these DBAs have been kind enough to share the wealth with their peers. Following this trend, we’ve packaged up our own set of scripts and modules into an open source collection we call the PDBA Toolkit. As a side benefit, the toolkit provides us with a living breathing entity whose code we can use to illustrate the use of Perl. We describe this toolkit in Part III of this book.

Data-processing scripts

Many Oracle DBAs spend at least part of their time dealing with data warehousing as well as database administration. They often need to clean and transform data that originates in other databases and applications and is now destined for Oracle. Perl, with its regular expressions and high performance, is one of the best solutions around for preparing data for use in data warehouse applications. Data munging is the term used to describe the data cleaning, formatting, and transformation often required by data warehouses. Appendix C, provides an essential guide to Perl regular expressions, and Appendix D, summarizes the many Perl modules available to perform data-processing and data-munging operations on all kinds of data, including numeric, text, date, and XML formats.

Custom scripts

Helpful as all of these packaged solutions may be, DBAs often find it necessary to write their own custom queries and scripts to solve their immediate problems. Every DBA ends up needing to write quick 5- or 10-line ad hoc programs simply to glue things together in their databases. They also may find that the canned applications and tools available for Oracle are great, but not quite right for their needs. The nice thing about Perl is that it makes it easy for you to add, change, or customize. All of the applications we describe throughout this book are available in source form so you can modify them to suit your needs. Our own toolkit is designed specifically to accommodate such customization. The modular nature of the scripts, coupled with the documentation provided in Part III of this book (see Chapter 13, in particular) should make it easy for you. You’ll also find the appendixes helpful in learning the basics of Perl.

Table 1-3 lists all of the applications and tools mentioned in this book. We tried to include the most up-to-date information possible in this book at the time of publication, but because most of these programs are continually being enhanced, make sure to check out the sites listed in the table for current information.

Table 1-3. Perl/Oracle applications and related tools

Application/tool

Chapter

Description/download site

ActivePerl

1

Precompiled binary Win32 Perl from ActiveState

http://www.activestate.com

http://aspn.activestate.com/ASPN/Downloads/

http://aspn.activestate.com/ASPN/PPM/FAQ

http://downloads.activestate.com/

Apache

4

Apache web server software

http://www.apache.org/

http://httpd.apache.org/

http://httpd.apache.org/dist/httpd/

http://httpd.apache.org/docs/windows.html

http://httpd.apache.org/dist/httpd/binaries/win32/

http://httpd.apache.org/docs/mod/directives.html

Apache mod_perl

5

Apache Perl integration

http://perl.apache.org/

http://www.cpan.org/authors/id/DOUGM/

http://www.modperl.com/

http://www.refcards.com/about/mod_perl.html

http://theoryx5.uwinnipeg.ca/ppmpackages (Win32)

http://theoryx5.uwinnipeg.ca/guide/

http://mathforum.org/epigone/modperl

Apache::DBI

5

Caching Perl DBI connections with mod_perl

http://www.cpan.org/authors/id/MERGL/

Apache::OWA

5

Linking Perl to Oracle’s PL/SQL Web Toolkit

http://sourceforge.net/projects/owa/

http://owa.sourceforge.net/

http://www.cpan.org/authors/id/S/SV/SVINTO

http://www.cpan.org/authors/id/J/JI/JIMW/ (libapreq)

http://technet.oracle.com

http://technet.oracle.com/doc/windows/was.21/psqlwtlk.htm [a]

CPAN (2000+ packages)

1

The Comprehensive Perl Archive Network

http://www.cpan.org

http://search.cpan.org

Cygwin (and DJGPP)

2

Unix-like environments for Win32

http://www.cygwin.com/

http://cygwin.com/cygwin-ug-net/using-cygwinenv.html

http://www.delorie.com/djgpp/

DBD::Chart (see also, zlib, gd, and PNG)

3

SQL-like chart generation using Perl DBI

http://www.presicient.com/dbdchart/

http://www.cpan.org/authors/id/D/DA/DARNOLD/ftp://ftp.uu.net/graphics/jpeg

http://www.ijg.org/

http://www.cpan.org/authors/id/NI-S/ (Tk::JPEG)

DDL::Oracle

3

Perl package for specific Oracle DDL generation

http://sourceforge.net/projects/ddl-oracle/

http://www.cpan.org/authors/id/R/RV/RVSUTHERL/

Embperl (see also HTML::Template and Mason)

6

HTML embedded Perl system

http://perl.apache.org/embperl/

http://www.cpan.org/authors/id/GRICHTER/ (Apache::SessionX and stable Embperl source)http://www.cpan.org/authors/id/A/AM/AMS/ (Storable)

http://www.cpan.org/authors/id/JBAKER/ (Apache::Session)http://theoryx5.uwinnipeg.ca/ppmpackages (Win32)

Exception (see also Perl GUI debuggers)

B

Java-like try and catch structures in Perl

http://www.cpan.org/authors/id/P/PJ/PJORDAN/

extproc_perl (see also Perl DBI)

8

Oracle Perl Procedure Library (Perl linkage to PL/SQL)

http://www.smashing.org/

http://www.cpan.org/modules/by-authors/Jeff_Horwitz

http://technet.oracle.com

http://download.oracle.com/otndoc/oracle9i/901_doc/appdev.901/a88876/adg11rtn.htm

http://download.oracle.com/otndoc/oracle9i/901_doc/server.901/a90117/manproc.htm

http://otn.oracle.com/deploy/security/alerts.htm (Oracle security alerts)

gcc (see also Unix freeware)

2

GNU C compiler

http://www.gnu.org/

gd (see also PNG and zlib)

3

Graphics drawing packages with Perl

http://www.cpan.org/authors/id/LDS/

http://www.boutell.com/gd/ (gd)

gdb (see also gcc)

8

GNU debugger (for particular usage with gcc)

http://www.gnu.org/software/gdb/

HTML::Template (and Template Toolkit) (see also Embperl and Mason)

6

HTML embedded Perl system

http://www.cpan.org/authors/id/S/SA/SAMTREGAR/

http://www.cpan.org/authors/id/ABW/

http://www.openinteract.org/

http://openinteract.sourceforge.net/

http://perl.apache.org/features/tmpl-cmp.html

Karma

4

Web tool for Oracle DBAs

http://hypno.iheavy.com/karma/index.html

http://www.cpan.org/authors/id/M/MA/MARKOV/ (MailTools)

http://www.cpan.org/authors/id/KJALB/ (TermReadKey)

http://www.cpan.org/authors/id/GBARR/ (libnet)

LWP

5

Library for WWW access in Perl

http://www.cpan.org/authors/id/GAAS/ (LWP,URI,MIME::Base64,HTML::Parser, Digest::MD5)

http://www.cpan.org/authors/id/S/SB/SBURKE/ (HTML::Tagset)

http://www.cpan.org/authors/id/GBARR/ (libnet)

http://www.cpan.org/authors/id/KWILLIAMS/ (HTML::SimpleParse)

Linux packages

2

Linux application and package download sites

http://www.redhat.com/apps/download/

http://www.suse.de/us/support/download/

http://www.linux-mandrake.com/en/ftp.php3

http://www.caldera.com/download/mirrors.html

http://www.debian.org/distrib/ftplist

http://www.turbolinux.com/download/

http://www.slackware.com/packages/

MSI (as standard from Win2000 onward)

2

Microsoft software package installer

http://download.microsoft.com/download/platformsdk/wininst/1.1/NT4/EN-US/InstMsi.exe

http://download.microsoft.com/download/platformsdk/wininst/1.1/W9X/EN-US/InstMsi.exe

Mason (see also HTML::Template and Embperl)

6

HTML embedded Perl

http://www.masonhq.com/

http://www.cpan.org/authors/id/J/JS/JSWARTZ/

http://www.cpan.org/authors/id/DEWEG/ (Time::HiRes)

http://www.cpan.org/authors/id/GSAR/ (MLDBM)

http://www.cpan.org/authors/id/ILYAZ/modules/ (FreezeThaw)

http://www.cpan.org/authors/id/A/AM/AMS/ (Storable)

http://www.cpan.org/authors/id/D/DR/DROLSKY/ (Params::Validate)

MySQL

D

Open source database

http://www.mysql.com/

http://sourceforge.net/projects/mysql/

http://www.cpan.org/authors/id/JWIED/ (DBD::mysql)

NMAKE (see also ActivePerl)

6

Pure Perl Win32 package compilation

http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe

OraExplain (see also Perl DBI)

3

Perl/Tk Oracle SQL tuning tool

http://www.cpan.org/authors/id/TIMB/

Orac

3

Perl/Tk general Oracle DBA tool

http://www.cpan.org/authors/id/A/AN/ANDYDUNC/

Oracle::OCI

7

Direct Perl interface to Oracle Call Interface

http://www.perl.com/CPAN/authors/id/TIMB/

http://archive.develooper.com/oracle-oci@perl.org/

http://www.cpan.org/authors/id/T/TB/TBONE/ (Data::Flow)

http://www.cpan.org/authors/id/HVDS/ (C::Scan)

http://technet.oracle.com

http://technet.oracle.com/tech/oci/

http://otn.oracle.com/tech/oci/htdocs/faq.html

http://www.orafaq.org/faqoci.htm

Oracletool

4

General web tool for Oracle DBAs

http://www.oracletool.com/

http://www.cpan.org/authors/id/GAAS/ (Digest::MD5)

http://www.cpan.org/authors/id/D/DP/DPARIS/ (Crypt::IDEA and Crypt::Blowfish)

http://www.cpan.org/authors/id/LDS/ (Crypt::CBC)

PNG (see also zlib and gd)

3

Portable Network Graphics (GIF image alternative)

http://www.libpng.org/pub/png/

http://www.cpan.org/authors/id/NI-S/ (Tk::PNG)

Perl

1

The main Perl portals and download sites

http://www.perl.com

http://www.perl.org

http://www.perl.com/CPAN/README.html

http://www.perl.com/CPAN/src/stable.tar.gz

http://learn.perl.org/

http://history.perl.org/

http://www.wall.org

http://lists.perl.org/

http://archive.develooper.com/

Perl DBA Toolkit (see also DDL::Oracle)

9

Our Perl toolkit for Oracle DBAs

http://www.oreilly.com/catalog/oracleperl

http://www.oreilly.com/catalog/oressentials/chapter/defrag.pdf

http://www.cpan.org/authors/id/GBARR/ (TimeDate)

http://www.cpan.org/authors/id/S/SI/SIFUKURT/ (Crypt::RC4)

http://www.cpan.org/authors/id/M/MI/MIVKOVIC/ (Mail::Sendmail)

http://www.cpan.org/authors/id/SBECK/ (Date::Manip)

http://www.roth.net (Win32::Daemon)

Perl DBI and DBD::Oracle

1

Perl DBI portals and resources

http://dbi.perl.org

http://dbi.perl.org/doc/faq.html

http://xmlproj.dyndns.org/dbi/faq.html

http://archive.develooper.com/dbi-users@perl.org/

http://www.xray.mpe.mpg.de/mailing-lists/dbi/

http://xmlproj.com/PPM/ (latest Win32 packages)

http://www.perl.com/CPAN/modules/by-module/DBI

http://www.perl.com/CPAN/modules/by-module/DBD

http://www.cpan.org/authors/id/TIMB/

Perl DBI ProxyServer(version numbers may change; if so, try http://search.cpan.org)

2

Proxy serving for Perl DBI

http://search.cpan.org/doc/TIMB/DBI-1.20/lib/DBI/ProxyServer.pm

http://search.cpan.org/doc/TIMB/DBI-1.20/lib/DBD/Proxy.pm

http://www.cpan.org/authors/id/A/AM/AMS/ (Storable)

http://www.cpan.org/authors/id/JWIED/ (Net::Daemon and PlRPC — which contains RPC::PlServer and RPC::PlClient)

Perl GUI debuggers (see also Exception)

3

Perl GUI debug tools

http://members.tripod.com/~CurtMcKelvey/perldbgui/ (perldbgui)

http://www.cpan.org/authors/id/A/AE/AEPAGE/ (ptkdb)

http://sourceforge.net/projects/open-perl-ide/ (OpenPerlIDE)

Perl IDE tools

3

Perl GUI development tools

http://sourceforge.net/projects/open-perl-ide/ (OpenPerlIDE)

http://sourceforge.net/projects/kpad/ (KakePad)

http://www.xarka.com/optiperl/ (OptiPerl)

http://www.activestate.com/Products/Komodo/ (Komodo)

http://www.ultraedit.com/ (UltraEdit)

Perl SQL tools (see also Senora)

3

SQL*Plus-like Perl tools

http://www.perldoc.com/perl5.6.1/lib/DBI/Shell.html

http://dbishell.sourceforge.net/

http://piqt.sourceforge.net/

http://sourceforge.net/projects/dsql/

Perl XML (see later for specific XML Perl modules)

D

Perl XML resources

http://www.xml.com/pub/q/perlxml

http://xmlxslt.sourceforge.net/

http://perl.apache.org http://xml.sergeant.org/

http://www.xmlsoft.org/

http://www.xmlproj.com/perl-xml-faq.dkb

http://www.perlxml.net http://www.cpan.org/modules/by-module/XML/

http://sourceforge.net/projects/perl-xml:

Perl conversion modules

D

Perl’s main data conversion modules

http://www.gnu.org/software/recode/recode.html,ftp://ftp.gnu.org/gnu/recode/

http://www.cpan.org/authors/id/CXL/ (Convert::EBCDIC)

http://www.cpan.org/authors/id/COLINK/ (Convert::SciEng)

http://www.cpan.org/authors/id/GENJISCH/ (Convert::Translit)

http://www.cpan.org/authors/id/R/RR/RRWO/ (Convert::Units)

http://www.cpan.org/authors/id/ANDK/ (Convert::UU)

http://www.cpan.org/authors/id/E/ED/EDAVIS/ (Convert::Recode)

Perl date modules (and other required helper packages)

D

Perl’s major date-handling modules

http://www.cpan.org/authors/id/D/DE/DESIMINER/ (Date::Business)

http://www.cpan.org/authors/id/STBEY/ (Date::Calc and Date::Pcalc)

http://www.cpan.org/authors/id/H/HF/HFB/ (Date::Christmas)

http://www.cpan.org/authors/id/M/MI/MIDI/ (Date::Decade)

http://www.cpan.org/authors/id/RBOW/ (Date::Easter)

http://www.cpan.org/authors/id/B/BB/BBEAUSEJ/ (Date::Handler)

http://www.cpan.org/authors/id/M/MI/MIYAGAWA/ (Date::Japanese::Era)

http://www.cpan.org/authors/id/JTOBEY/ (Date::Simple)

http://www.cpan.org/authors/id/T/TM/TMTM/ (Date::Range)

http://www.cpan.org/authors/id/SBECK/ (Date::Manip)

http://www.cpan.org/authors/id/B/BZ/BZAJAC/ (DateTime::Precise)

http://www.cpan.org/authors/id/GAAS (Mime::Base64)

http://www.cpan.org/authors/id/D/DA/DANKOGAI (Jcode)

http://www.cpan.org/authors/id/ADESC (Devel::CoreStack)

http://www.cpan.org/authors/id/MSCHWERN (Test::Harness and Test::Simple)

Perl numeric modules

D

Perl’s major numeric modules

http://www.cpan.org/authors/id/L/LU/LUISMUNOZ/ (Number::Encode)

http://www.cpan.org/authors/id/WRW/ (Number::Format)

http://www.cpan.org/authors/id/S/SB/SBURKE/ (Number::Latin)

http://www.cpan.org/authors/id/K/KE/KENNEDYH/ (Number::Phone::US)

http://www.cpan.org/authors/id/W/WI/WIMV/ (Number::Spice)

http://www.cpan.org/authors/id/L/LH/LHOWARD/ (Number::Spell)

Perl/Tk

3

Perl GUI toolkit (derived originally from Tcl/Tk)

http://www.lehigh.edu/~sol0/ptk/ptk.html

http://www.perltk.org/

http://www.oreilly.com/catalog/mastperltk/

http://www.cpan.org/authors/id/NI-S/

http://www.cpan.org/authors/id/SREZIC/

SSL

5

Secure Sockets Layer for Perl and the Web

http://www.openssl.org/ (OpenSSL)

http://www.cpan.org/authors/id/C/CH/CHAMAS/ (Crypt::SSLeay)

http://www.cpan.org/authors/id/SAMPO/ (Net::SSLeay)

http://www.cpan.org/authors/id/A/AS/ASPA/ (IO::Socket::SSL)

SchemaDiff

3

DDL::Oracle and Perl/Tk Oracle schema comparisons

http://sourceforge.net/projects/schemadiff/

SchemaView-Plus (see also XML::Dumper and XML:: Parser)

3

Perl/Tk Oracle tool for viewing schema connections

http://www.cpan.org/authors/id/M/MI/MILSO

http://dbman.linux.cz (dbMan, earlier related tool)

Senora (see also Perl SQL tools)

3

DDL::Oracle-based SQL*Plus-like tool

http://sourceforge.net/projects/senora/

StatsView (see also PNG, zlib, OraExplain)

3

Perl/Tk statistics for Oracle on Unix

http://www.cpan.org/authors/id/ABURLISON/

http://www.gnuplot.info/

http://sourceforge.net/projects/gnuplot/

Unix freeware (also good sources for gcc binary packages; see also gcc)

2

Binary Perl packages for Unix

http://sunfreeware.com/ (Solaris)

http://ftp.univie.ac.at/aix/andftp://aixpdslib.seas.ucla.edu/pub/ (AIX)

http://jazz.external.hp.com/src/index.html (HP-UX)

http://freeware.sgi.com/index.html (IRIX)

http://www.openbsd.org/ports.html (OpenBSD)

XML::Dumper

3

Dump Perl data to structured XML

http://www.cpan.org/authors/id/E/EI/EISEN

XML::Generator::DBI

D

DBI and XML linkage package

http://www.cpan.org/authors/id/M/MS/MSERGEANT

http://www.cpan.org/authors/id/KMACLEOD/ (libxml-perl and XML::Parser::PerlSAX)

http://www.cpan.org/authors/id/K/KR/KRAEHE/ (XML::Handler::YAWriter)

http://www.cpan.org/authors/id/GAAS/ (MIME::Base64)

XML::LibXML

D

Alternative Perl XML parser

http://www.cpan.org/authors/id/M/MS/MSERGEANT/ (XML::LibXML and XML::Sax)

http://www.xmlsoft.org (libxml2)

XML::LibXSLT

D

Perl Extensible Stylesheet Language Transformations

http://www.cpan.org/authors/id/M/MS/MSERGEANT/ (XML::LibXSLT)

http://xmlsoft.org/XSLT/downloads.html (libxslt)

http://www.w3.org/TR/xslt

http://xmlsoft.org/XSLT/

XML::Parser

3

Perl XML parser

http://sourceforge.net/projects/expat (CXMLparser)

http://www.cpan.org/authors/id/C/CO/COOPERCL

XML::XMLtoDBMS (see also XML::Parser and XML::LibXML)

D

The Perl port of XML-DBMS from Java

http://www.rpbourret.com/xmldbms/index.htm (Perl port accessed from this page)

http://www.cpan.org/authors/id/GBARR/ (TimeDate)

XML::XPath (see also XML::Parser)

D

Perl and XPath

http://www.cpan.org/authors/id/M/MS/MSERGEANT

http://www.w3.org/TR/xpath

zlib (see also PNG)

3

Gzip’s back-end compression library

http://www.gzip.org/zlib/

http://www.zlib.org

http://www.gzip.org/

http://www.info-zip.org/pub/infozip/

http://www.pkware.com/

[a] As with most http://technet.oracle.com pages, this requires password-protected membership, which can be freely acquired from http://technet.oracle.com/membership/.

For Further Information

We’ve collected what we consider to be the best online and offline resources for Perl in the following sections. If you run into problems or just want to expand your horizons, do check out the books, web sites, and mailing lists summarized here.

Further Information on Perl

Appendix A summarizes the essential elements of Perl’s syntax, up to and including its object orientation. It also provides a full guide to the use of the very helpful perldoc command, which is the best way to access online manual page information on Perl once it has been installed.

Perl web sites

The following web sites provide good springboards into the world of Perl:

http://www.perl.com

Contains everything you ever wanted to know about Perl.

http://www.perl.org

Another central resource for Perl users.

http://learn.perl.org

Site dedicated to people fresh to Perl.

http://history.perl.org
http://www.wall.org

Information on the history of Perl.

Perl mailing lists

One of the wonderful benefits of open source tools like Perl is the large number of people out there willing to help you. There are literally hundreds of Perl mailing lists to choose from. Fortunately, there is one site for keeping tabs on all of them:

http://lists.perl.org

An excellent central resource for tracking down virtually every kind of Perl mailing list you could possibly think of.

Send a blank email here to get attached to the Perl beginners’ mailing list.

Once registered, you can post your questions here.

When you’re ready to move on to other lists, you can unsubscribe by sending another blank email to the preceding address.

http://archive.develooper.com

Before posting any questions, you may want to check the Perl archive first.

Perl books

There are enough books on Perl to fill the capacious saddles of several very large camels. Here we’ll list just a few of our favorite general texts.

http://www.oreilly.com/catalog/lperl3 (the Llama book)

Learning Perl, by Randal L. Schwartz and Tom Christiansen, 3rd ed. (O’Reilly & Associates, 2001)

http://www.oreilly.com/catalog/lperlwin (the Gecko book)

Learning Perl on Win32 Systems, by Randal L. Schwartz, Erik Olson, and Tom Christiansen (O’Reilly & Associates, 1997)

http://www.oreilly.com/catalog/pperl3 (the Camel book)

Programming Perl, by Larry Wall, Tom Christiansen, and Jon Orwant, 3rd ed. (O’Reilly & Associates, 2000)

http://www.roth.net/books/extensions2

Win32 Perl Programming: The Standard Extensions, by Dave Roth, 2nd ed. (New Riders Publishing, 2001)

http://www.oreilly.com/catalog/perlnut

Perl in a Nutshell, by Ellen Siever, Stephen Spainhour, and Nathan Patwardhan (O’Reilly & Associates, 1998)

http://www.oreilly.com/catalog/advperl (the Panther book)

Advanced Perl Programming, by Sriram Srinivasan (O’Reilly & Associates, 1997)

http://www.effectiveperl.com (the Shiny Ball book)

Effective Perl Programming: Writing Better Programs with Perl, by Joseph N. Hall (Addison-Wesley, 1998)

http://www.oreilly.com/catalog/regex (the Owls book)

Mastering Regular Expressions: Powerful Techniques for Perl and Other Tools, by Jeffrey Friedl (O’Reilly & Associates, 1997)

http://www.manning.com/Conway/index.html (the Renaissance book)

Object Oriented Perl, by Damian Conway (Manning, 1999)

Further Information on Perl DBI

If you want to learn more about Perl DBI, first check out Appendix B. It’s likely you’ll need more detailed information, however, if you’re planning to do anything complex. Here are some recommended resources.

Perl DBI web sites

The following sites are the best places to go for more information:

http://dbi.perl.org

Central home page for the Perl DBI project and the best place to start

http://dbi.perl.org/doc/faq.html

Central FAQ for Perl DBI

Perl DBI mailing lists

The DBI Users mailing list is the information backbone for the entire DBI community, and you’ll find a great deal of help available there. However, it’s generally considered good form if you at least search the DBI FAQ located at http://dbi.perl.org/doc/faq.html, and possibly the following mail archives, before posting any new questions:

http://lists.perl.org/showlist.cgi?name=dbi-users

The folks at perl.org maintain the DBI Users mailing list, and you can register yourself with them at this web address.

To subscribe to the mailing list, send an empty email here.

Once you’ve been successfully registered by http://perl.org, you can post your Perl DBI questions and comments via this email link.

To unsubscribe from the mailing list, post an empty email here.

http://archive.develooper.com/dbi-users@perl.org

The main archive attached to the central DBI Users mailing list, organized by date and threaded topic.

http://www.xray.mpe.mpg.de/mailing-lists/dbi

Another searchable archive for the DBI mailing list. Again, you may want to search through this archive before posting any new mailing list questions.

Perl DBI books

Two O’Reilly books complement the one you’re reading right now. The first contains much more detail on the Perl DBI API; the second also describes Perl DBI, as well as many other open source technologies (including Tcl and Python) and their parallel use of OCI:

http://www.oreilly.com/catalog/perldbi

Programming the Perl DBI: Database Programming with Perl, by Alligator Descartes and Tim Bunce (O’Reilly & Associates, 2000).

http://www.oreilly.com/catalog/oracleopen

Oracle & Open Source: Tools and Applications, by Andy Duncan and Sean Hull (O’Reilly & Associates, 2001).



[3] The camel is a great image for Perl because it suggests a horse designed by more than one voice — perhaps a bit challenged in looks, but perfectly adapted for a difficult ecological niche.

Get Perl for Oracle DBAs now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.