An Introduction to Perl
Preliminaries
The following are some initial comments about Perl. The
goal of these are to give you a feeling for the language and whay you should
care about learning it.
- Perl stands for Practical Extraction and Extraction
Language.
- Perl has a very loyal following. Some say a cult-like
following. There is a community of Perl programmers out ther with a very
welcomming attitude to new comers.
- Perl was released on October 18, 1987 by Larry Wall.
It is freeware.
- Perl is derived from C, but you will see other influences
including BASIC, awk (UNIX utility for pattern scanning.), sed (UNIX stream
editor utility.), and the UNIX shell.
- It will be an easy language for us to learn given our
background. It might not be as easy to master.
- Its area of strength is manipulating text files and system
processes.
- It is very concise. There are amazing things that can
be done in one line. E.g. Reverse the order of the lines in a file.
- People have developed impressive applications quickly.
I have a friend who developed an entire trading system in Perl.
- It continues to be freeware with a community of people
adding features. Web applications and database applications have been
developed in Perl. Much of the functionality has been added through
modules. These are like libraries.
- The current version of Perl is version is 5.9.3. It is
free and can be downloaded.
- Perl was originally written for UNIX, but it has been ported
to other system.
- Perl is an interpreted language. It translates to a
byte code which is interpreted. So, one can expect it to run slower than
C or C++. But, unless the program is CPU bound, this might not be a
factor.
- There are man pages for Perl. Start with "man perl"
and it will give you lots of pages to view.
- We will only discuss running Perl on UNIX. There are
slight differences running it on other OSs.
- We are using the book "Learning Perl" by Schwartz and
Phoenix, published by O'Reilly.
- Perl is a good tool to quickly knock out an application.
- You can write extremely ugly code in Perl.
- Larry Wall must have hated to type.
- Perl has few limitations. For example, there is no
limit on the maximum length string.
Our First Program
To be in line with the rest of the world, our first program
will display "Quack Quack"
#!/usr/bin/perl -w
# Ducks are good!
print "Quack Quack\n";
Note:
- #!/usr/bin/perl -w is interpreted by the shell as the
path to the Perl interpreter. The -w is one of the Perl flags to give us
warnings if we are doing weird things. There are other flags. -t
for trace may be useful
- It is good to use the .pl extension. It lets emacs
know that we are editing a Perl program.
- # indicates a comment.
- The print statement has the same format as the printf
from C++. If you don't remember it, I will fill you in as we go along.