PERL Tutorial (Practical Extraction and Report Language)
Posted: Thu Oct 01, 2009 1:23 am
This tutorial will guide you to learn the basics of PERL and its syntax. In our examples we would be incorporating our PERL scripts with HTML, CSS, and PHP. Lets start with a quick history of PERL, its file types and its importance.
Perl History
PERL is a UNIX based language and was created in 1987 by Larry Wall. It was originally created for UNIX based systems and it gradually evolved into a powerful tool for the internet.
PERL is very simple and short. Due to its value added features like flexibility, portability and easy usage its popularity increased. Nowadays PERL is widely used to automate several tasks.
Getting started
Visit perl.org and download the latest version of PERL. This tutorial is web based and we recommend you to check with your web host if PERL is installed on the server and find its path.
You can use any text editor ( vi, notepad ) to write your PERL scripts.
PERL file extensions
A PERL file must be save with a .pl extension. The file can contain letters, numbers and symbols but must not contain a space.
The other extensions you may come across are:
The main features of PERL are:
The first line of every PERL script is a commented line directed toward the interpreter.
firstperlscript.pl:
#!/usr/bin/perl
Lets start with a simple script to print " Hello World "
Example:
Save it as " firstperlscript.pl ".
In Unix / Linux you will need to give execute permissions for your scripts.
Examples:
$ chmod +x firstshellscript.pl
or
$ chmod 755 firstshellscript.pl
How to run the PERL script:
In Unix / Linux / Windows
perl firstshellscript.pl
Now lets try the same example in the web environment.
We need to add the http headers so that Perl understands we are working with a web browser.
Example:
How to run the above script in web environment:
You need to upload the firstperlscript.pl file to your hosting account via FTP.
Chmod it to 755 and access this file using browser.
If everything is fine, the browser should displays " Hello World ".
Perl History
PERL is a UNIX based language and was created in 1987 by Larry Wall. It was originally created for UNIX based systems and it gradually evolved into a powerful tool for the internet.
PERL is very simple and short. Due to its value added features like flexibility, portability and easy usage its popularity increased. Nowadays PERL is widely used to automate several tasks.
Getting started
Visit perl.org and download the latest version of PERL. This tutorial is web based and we recommend you to check with your web host if PERL is installed on the server and find its path.
You can use any text editor ( vi, notepad ) to write your PERL scripts.
PERL file extensions
A PERL file must be save with a .pl extension. The file can contain letters, numbers and symbols but must not contain a space.
The other extensions you may come across are:
- .pm - Perl module
- .ph - Perl header
- .pod - Perl documentation ( POD stands for Plain Old Documentation)
The main features of PERL are:
- Perl is free.
- Perl is simple to learn, concise and easy to read
- Perl is fast
- Perl is extensible
- Perl has flexible data types
- Perl is object oriented
- Perl is collaborative
The first line of every PERL script is a commented line directed toward the interpreter.
firstperlscript.pl:
#!/usr/bin/perl
Lets start with a simple script to print " Hello World "
Example:
Code: Select all
#!/usr/bin/perl
print "Hello World"
In Unix / Linux you will need to give execute permissions for your scripts.
Examples:
$ chmod +x firstshellscript.pl
or
$ chmod 755 firstshellscript.pl
How to run the PERL script:
In Unix / Linux / Windows
perl firstshellscript.pl
Now lets try the same example in the web environment.
We need to add the http headers so that Perl understands we are working with a web browser.
Example:
Code: Select all
#!/usr/bin/perl
print "content-type: text/html \n\n";
print "Hello World!";
You need to upload the firstperlscript.pl file to your hosting account via FTP.
Chmod it to 755 and access this file using browser.
If everything is fine, the browser should displays " Hello World ".