The next section on Perl's origin is very short. You can read all the background information at http://www.perl.com-the Perl home page.
Back in 1986, Larry Wall invented the Perl language as an interpreter on UNIX. The new language had an emphasis on system management and text handling. After a few revisions, it could handle regular expressions, signals, and network sockets too.
Perl can handle low-level tasks quite well, particularly since Perl 5 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.
It's not completely "public domain". It 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.
It is very easy to see if your system already has Perl installed. Simply go to a command-line prompt and type:
perl -v
The response will be similar to this:
This is perl, version 5.004_04 built for irix-n32 Copyright 1987-1997, Larry Wall 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.
Each operating system has its own way of getting and installing 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/98/2000/Windows NT, the home page of hip communications, inc. (http://www.perl.hip.com) contains a link to download the i86 Release Binary. This link lets you download a zip file that contains the Perl files in compressed form.
Instructions for compiling Perl or for installing on each operating system are included with the distribution files. Follow the instructions provided and you should having a working Perl installation rather quickly.
Perl code can be quite free-flowing. The broad syntactic rules governing where a statement starts and ends are:
print("Hello World!\n");
Perl runs this code and prints out Hello World!. \n simply means that Perl should print a newline character after the text, or in other words, go to the start of the next line.
Printing more text is a matter of either stringing together statements like this, or giving multiple arguments to the print() function:
print("My name is Jun Ni,\n");
print("I am an instructor and\n", "I am teaching Perl programming language.\n");
So what does a complete Perl program look like? Here's a small example, complete with the invocation line at the top and a few comments:
#!/usr/local/bin/perl -w
print("My name is Jun Ni,\n");
print("I am an instructor and\n", "I am teaching Perl programming language.\n");
That's not at all typical of a Perl program, though; it's just a linear sequence of commands with no complexity.
You can create your Perl program by starting any text processor:
perl filename.pl
For example,
perl test.pl
This example assumes that perl is in the execution path; if not, you will need to supply the full path to perl too. For example, on UNIX the command might be:
/usr/local/hin/perl test.pl
Whereas on Windows, you might need to use:
c:\perl5\bin\perl test.pl
UNIX systems have another way to invoke a program. However, you need to do two things. The first is to place a line like
#!/usr/local/bin/perlat the start of the Perl file. This tells UNIX that the rest of this script file is to be run by /usr/local/bin/perl. The second step is to make the program file itself executable by changing its mode:
chmod +x test.plNow you can execute the program file directly and let the program file tell the operating system what interpreter to use while running it. The new command line is simply:
test
Comments are placed inside a program file using the # character. Everything after the # is ignored. For example:
# This is whole line is ignored.
print("Perl is easy.\n"); # Here's a half-line comment.