10
A BRIEF STUDY OF “PERL”

A Brief Study of Perl

Embed Size (px)

DESCRIPTION

History

Citation preview

A BRIEF STUDY OF

PERL

Table of Contents

1. Introduction

INTRODUCTION

What is Perl?

Perl is a programming language which can be used for a large variety of tasks. A typical simple use of Perl would be for extracting information from a text file and printing out a report or for converting a text file into another form. But Perl provides a large number of tools for quite complicated problems, including systems programming.

Programs written in Perl are calledPerl scripts, whereas the termthe perl programrefers to the system program named perl for executing Perl scripts. (What, confused already?)

If you have used shell scripts orawkorsedor similar (Unix) utilities for various purposes, you will find that you can normally use Perl for those and many other purposes, and the code tends to be more compact. And if you haven't used such utilities but have started thinking you might have need for them, then perhaps what you really need to learn is Perl instead of all kinds of futilities.

Perl is implemented as an interpreted (not compiled) language. Thus, the execution of a Perl script tends to use more CPU time than a corresponding C program, for instance. On the other hand, computers tend to get faster and faster, and writing something in Perl instead of C tends to saveyourtime.

Origin of language :

Perl began as the result of one man's frustration and, by his own account, inordinate laziness. It is a unique language in ways that cannot be conveyed simply by describing the technical details of the language. Perl is a state of mind as much as a language grammar.

One of the oddities of the language is that its name has been given quite a few definitions. Originally, Perl meant the Practical Extraction Report Language. However, programmers also refer to is as the Pathologically Eclectic Rubbish Lister. Or even, Practically Everything Really Likable.

Back in 1986, Larry Wall found himself working on a task which involved generating reports from a lot of text files with cross references. Being a UNIX programmer, and because the problem involved manipulating the contents of text files, he started to use awk for the task. But it soon became clear that awk wasn't up to the job; with no other obvious candidate for the job, he'd just have to write some code.

Larry could have just written a utility to manage the particular job at hand and gotten on with his life. He could see, though, that it wouldn't be long before he'd have to write another special utility to handle something else which the standard tools couldn't quite hack. (It's possible that he realized that most programmers werealwayswriting special utilities to handle things which the standard tools couldn't quite hack.)

So rather than waste any more of his time, he invented a new language and wrote an interpreter for it. If that seems like a paradox, it isn't really-it's always a bit more of an effort to set yourself up with the right tools, but if you do it right, the effort pays off.

Similar to C ?

Perl programs bear a passing resemblance to C programs, perhaps because Perl was written in C, or perhaps because Larry found some of its syntactic conventions handy. But Perl is less pedantic and a lot more concise than C.

Perl can handle low-level tasks quite well, particularly since Perl 5, when the whole messy business of references was put on a sound footing. In this sense, it has a lot in common with C. But Perl handles the internals of data types, memory allocation, and such automatically and seamlessly.

This habit of picking up interesting features as it went along-regular expressions here, database handling there-has been regularized in Perl 5. It is now fairly easy to add your favorite bag of tricks to Perl by using modules. It is likely that many of the added-on features of Perl such as socket handling will be dropped from the core of Perl and moved out to modules after a time

Cost and Licensing :

Perl is free. The full source code and documentation are free to copy, compile, print, and give away. Any programs you write in Perl are yours to do with as you please; there are no royalties to pay and no restrictions on distributing them as far as Perl is concerned.

It's not completely "public domain," though, and for very good reason. If the source were completely public domain, it would be possible for someone to make minor alterations to it, compile it, and sell it-in other words, to rip off its creator. On the other hand, without distributing the source code, it's hard to make sure that everyone who wants to can use it.

The GNU General Public License is one way to distribute free software without the danger of someone taking advantage of you. Under this type of license, source code may be distributed freely and used by anybody, but any programs derived using such code must be released under the same type of license. In other words, if you derive any of your source code from GNU-licensed source code, you have to release your source code to anyone who wants it. Perl is released under the terms of the "Artistic" license. This is a variation on the GNU General Public License which says that anyone who releases a package derived from Perl must make it clear that the package is not actually Perl. All modifications must be clearly flagged, executables renamed if necessary, and the original modules distributed along with the modified versions. The effect is that the original author is clearly recognized as the "owner" of the package. The general terms of the GNU General Public License also apply.

Installing Perl :

It's critically important to have Perl installed on your computer before reading too much further. As you read the examples, you'll want to try them. If Perl is not already installed, momentum and time will be lost.

It is very easy to see if your system already has Perl installed. Simply go to a command-line prompt and type:

perl -v

Hopefully, the response will be similar to this:

This is perl, version 5.001

Unofficial patchlevel 1m.

Copyright 1987-1994, Larry Wall

Win32 port Copyright 1995 Microsoft Corporation. All rights reserved.

Developed by hip communications inc., http://info.hip.com/info/

Perl for Win32 Build 107

Built Apr 16 1996@14:47:22

Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5.0 source kit.

If you get an error message or you have version 4 of Perl, please see your system administrator or install Perl yourself. The next section describes how to get and install Perl.

For UNIX and OS/2

-- The Perl Home Page contains a software link (http://www.perl.com/perl/info/software.html) that will enable you to download the latest Perl source code. The page also explains why Perl binaries are not available. Hopefully, your system will already have Perl installed. If not, try to get your system administrator to install it.

For Windows 95/Windows NT

-The home page of hip communications, inc. (http://www.perl.hip.com) contains a link to download thei86 Release Binary. This link lets you download a zip file that contains the Perl files in compressed form. CD-ROM copiess are freely distributed with many Perl books and also on CDROM: for example,Perl - Walnut Greek CD-ROM

For Macintosh Computers

--MacPerlis a ported version of Perl with a basic but very useable User Interface.It is available from

http://www.iis.ee.ethz.ch/neeri/macintosh/perlman/perl_toc.html,

http://www.unimelb.edu.au/ssilcot/macperl-primer/.

It also comes on CD-ROM with many Perl Books

Recommended Reading

Teach Yourself Web Publishing with HTML 3.2 in 14 Days,Laura Lemay, Sams.Net Publishing.

The Internet Unleashed,J. Ellsworth, B. Baron, et al., Sams.Net Publishing

The Internet Complete Reference(2nd Ed.),H. Hahn, McGraw-Hill

Webmaster in a Nutshell,S. Spainhour and V. Quercia, O'Reilly and Associates Inc.

Every Student's Guide to the World Wide Web,K. Pitter and R. Minato, McGraw Hill

HTML Sourcebook,I.S. Graham, Wiley and Sons

HTML: The Definitive Guide,C. Musciano and B. Kennedy, O'Reilly and Associates Inc.