An Introduction to Perl :
PERL (Practical Extraction and Report Language) written by Larry Wall
It has a rich variety of functions for handling strings, arrays, the system interface, networking and more.
Although it was originally from UNIX, Perl now runs on all operating systems like MS-DOS, Windows/NT, Mac, and many others.
The Perl motto is "there's more than one way to do it!"
Things to remember when writing Perl scripts :
- Executable files are types that contain instructions for the machine or an interpreter, such as Perl, to execute. To mark a file as executable, you need to alter the file permissions of the script file. There are three basic permissions: read, write, and execute. There are also three levels of access: user, group, and others. Perl files should have their permissions changed so that you, the user, has permission to read, write and execute your file, while others only have permission to read and execute your file. To do this use the "chmod" command:
chmod 755 filename.pl
- A perl script is a text file, it does not contain any machine code in it. So, it is important to tell Unix that this file must be parsed and executed by Perl. This is done by putting the following statement on the first line of the perl script:
#!/usr/bin/perl
which means that, the Perl executable, that parses and executes perl scripts is in the directory /usr/bin/. If you are not sure where the perl executable is, type in your command prompt
which perl
it will give you the path.
-
Perl file names end in .pl Just a convention, to make it easier for programmers.
- All statements end in a semicolon. Don't forget this!
- Comment lines begin with the '#' character
Now a small perl script for you to try.
Open a file called myfirst.pl in any text editors (eg, vi in unix edit in dos) and just type the following lines and save:
#!/usr/bin/perl
#Comment : This is my first perl script
print "A small perl script";
|
Now as I said earlier, you have to make the perl script executable so type in the command prompt
chmod 755 myfirst.pl
Now type,
perl myfirst.pl
The output will be,
A samll perl script
Why Perl?
Perl has become popular for many reasons, including:
-
Perl programs are more concise than C or shell
-
Perl is freely available for most platforms
-
Perl bridges the gap between shells and C
-
Perl includes functionality of sed and awk
-
Perl makes it easy to write secure programs
-
Perl allows for fast prototypes
-
interpreted = quick feedback
-
symbolic debugger included