Getting started with Perl, Part 1

Unix Insider |  Operating Systems

The Perl lobby has been strong and consistent, so it is high time for me to
provide an introduction to this language.

What is Perl? In the O'Reilly & Associates book Programming Perl, by Larry
Wall (the developer of the Perl language), Tom Christiansen, and Randal L.
Schwartz, the preface describes Perl as a programming language "that makes it
easy to manipulate numbers and text, files and directories, computers and
networks."

I quote from the developer of Perl here to defend myself in advance. There are Perl fanatics out there who will tell you that anything that you can say
about what the language does is too limiting,
since it can do anything better than any other language.

Perl is indeed a very nifty programming language and is easier to use than shell programming languages. It can be used to replace any shell program, and except in very simple cases, it does a much better job (and is easier to understand) than the shell version of the same thing. It certainly fulfills its promise of easy handling of text, numbers, and files.

It's also very flexible. In fact, the motto for Perl is "There's More Than One
Way To Do It." I am well aware that in the following examples nearly every
line of code could be written in about half a dozen different ways, but this is simply meant as an introduction. If you are a Perl expert and you feel there is a better way to do
one of these tasks, you may well be right. Please be patient.

If you do not have Perl on your system, then you should install
it. It is available by starting at http://www.perl.com/, the Perl home page
on the Web.

I have chosen a simple but illustrative project to begin with, which is easy in Perl, but devilishly difficult in shell script. This project will maintain
and allow lookups in a simple text file database of names and addresses. We'll need more than one installment, so let's get started.

If you are familiar with shell programming, then you have a head start on Perl. I'll start with the traditional greeting
program. The print command
prints a string and the \n indicates a new line in the printed string. Perl
commands end with a semi-colon. You can run this Perl script by saving it as
hello and typing perl hello.

Join us:
Facebook

Twitter

Pinterest

Tumblr

LinkedIn

Google+

Answers - Powered by ITworld

Ask a Question
randomness