What's Perl and why you should learn it?
PHP stands for Personal Homepage or Professional Homepage.
ASP stands for Active Server Page.
How about Perl?
What is Perl and why you should learn it?
What does "Perl" stand for?
"Perl", by definition, stands for Practical Extraction and Report Language.
Perl is a scripting language, that means, you can execute the codes on the fly when Perl runs the program. This is quite different from programs that require a compiler to compile it.
*** Since our focus is on Perl, if you are interested to find out the difference between scripting languages and compilation-based languages, there are many resources in the web.
The power of Perl
Perl was originally being used in Unix systems together with other Unix Tools and Languages such as Sed, Grep, Awk, Shell Scripting...
Perl, being strong in Regular Expression / Pattern Matching, it is used intensively by system administrators to do some daily jobs and it is useful for extracting content from a data file and format it in different patterns.
Using the following command you can easily sort out those files with a ".jsp" extension from a directory with hundreds of files:
@jspFiles = glob '.jsp';
*** Don't worry about the above script, onced you stay with me and reading throughout my daily Perl digest, you can finally find it is easily to understand.
Perl is also used with CGI for web programming just like what PHP is doing.
Your first Perl program:
#!/usr/bin/perl -w print "Hello, world!\n"; |
Explanation:
The above program is quite easy, right? For those who have programming experience, it should be a piece of cake. The program just print "Hello, world!" in the screen.
However, what I would like to explain is the first line:
#!/usr/bin/perl -w
For Perl programs (file with .pl extension) to be run, you first of all need to specify the where the Perl.exe is located. The first line in the program just specify the Perl.exe is located in the directory "/usr/bin/perl". "#!" is just the header parameter. "-w" means turn the warnings on so that the warnings will be printed on the console once you run the program.
Running the program:
Just copy the above codes to a text editor and save it as "hello.pl".
To run it, it is a little different in different Operating Systems and you have to modify the header (i.e. first line of the program) to specify the location of your Perl.exe.
If you are running the program in Unix, by default, "/usr/bin/perl" should be correct.
If you are running in Windows, you have to modify it. Sometimes, it may be located in "C:\perl\bin\perl.exe". Just make sure you are specifying the correct location.
After modifying, the first line may look like this:
#!C:\perl\bin\perl.exe -w |
Open the console or in command mode, change to the directory your "hello.pl" is located, type the following:
In Windows 9x:
In Windows XP/NT:
perl hello.pl
hello.pl
Conclusion:
Today you should have a general idea of Perl as well as its main purposes. You also have tasted your first Perl program and know how to run it.
Although I do not explicitly say why you should learn Perl, if your job needs it and if you need to do some extrations work and tired of using pattern matching in other programming languages (and of course there should be many other reasons), you will find it useful.
Enjoy Perl, keep an eye on this section.









