Section 1.1. What is Perl?

   

1.1 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.

1.1.1 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 BASICPLUS.) 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. [1]

[1] 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.

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.

1.1.1.1 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.

1.1.1.2 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.

1.1.1.3 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.

1.1.2 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.

Perl's Three Virtues

In the original Camel Book ” the latest edition is Programming Perl by Larry Wall, Tom Christiansen, and Jon Orwant, 3rd ed. (O'Reilly & Associates, 2000) ” Larry Wall identified three characteristics of virtuous programmers; these have become the most basic Perls of Wisdom among the faithful:

Laziness

From the Old English for "resistance to work," laziness is a virtue that makes you write labor-saving programs in order to avoid unnecessary effort. It also encourages good documentation to keep others from bothering you by asking impertinent questions.

Impatience

From the Latin for "unwillingness to endure waiting," impatience pushes you into change and arises from the restless injustice felt when computer applications are inefficient. It makes you write programs that match and even anticipate your needs.

Hubris

From the Greek for "excessive pride or wanton violence," hubris ensures that you create solutions that others say only good things about and that cut through any problem's resistance.

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 .

1.1.2.1 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.

1.1.2.2 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.

1.1.2.3 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.

1.1.2.4 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.

1.1.2.5 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"!

1.1.2.6 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.

1.1.2.7 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!

1.1.2.8 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.

   


Perl for Oracle DBAs
Perl for Oracle Dbas
ISBN: 0596002106
EAN: 2147483647
Year: 2002
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net