13-09-2012, 05:35 PM
A Quick, Painless Introduction to the Perl Scripting Language
PerlIntro.pdf (Size: 152.87 KB / Downloads: 69)
What Are Scripting Languages?
Languages like C and C++ allow a programmer to write code at a very detailed level which has good
execution speed. But in many applications one would prefer to write at a higher level. For example, for textmanipulation
applications, the basic unit in C/C++ is a character, while for languages like Perl and Python
the basic units are lines of text and words within lines. One can work with lines and words in C/C++, but
one must go to greater effort to accomplish the same thing. C/C++ might give better speed, but if speed is
not an issue, the convenience of a scripting language is very attractive.
Goals of This Tutorial
Perl is a very feature-rich language, which clearly cannot be discussed in full detail here. Instead, our
goals here are to (a) enable the reader to quickly become proficient at writing simple Perl programs and (b)
prepare the reader to consult full Perl books (or Perl tutorials on the Web) for further details of whatever
Perl constructs he/she needs for a particular application.
Our approach here is different from that of most Perl books, or even most Perl Web tutorials. The usual
approach is to painfully go over all details from the beginning. For example, the usual approach would be
to state all possible forms that a Perl literal can take on.
We avoid this here. Again, the aim is to enable the reader to quickly acquire a Perl foundation. He/she should
then be able to delve directly into some special topic, with little or not further learning of foundations.
The Tie Operation
(This is an advanced topic, and may be skipped by the general public without loss of continuity.)
Perl’s tie operation is a built-in function, tie().6 What it does is similar to operator overloading (though definitely
with differences). We will have what looks in our application code like an ordinary scalar variable,7
but internally the Perl interpreter will associate the variable with a reference to an instance of a class.8 The
value that the scalar seems to have in a casual look at the code will be actually be implemented as instance
variable in the class.