1. P age |1
PERL –Chap 1
Getting Started:
1. Perl – Practical Extraction and Report Language
2. Main site for learning Perl: http://www.perl.org
3. For Windows (x86 system), version installed :
ActivePerl5.12.13 site: www.activestate.com/activeperl
4. Install Perl – default location will be C:Perl
5. Perl – interpreter based
6. Mainly used for text-based work.
7. Caution!! – source code must be provided to user; Perl can’t create opaque binaries (binary files)
and so no privacy of source code.
8. More info on Perl, problems – google it!
My First Program in Perl
1. Create a folder : C:perlscripts
2. In Notepad, type the following:
#!/usr/bin/perl
print "Hello World.n";
print "Here I come";
Save this file as hello.pl in the folder perlscripts
Note: Filename extension is .pl
Run the program from DOS prompt and immediately the output is displayed like this:
C:perlscripts>hello.pl
Hello World
Here I come
C:perlscripts>
Caution: Some books may suggest that the filename extension of .pl is not required. But if filename
extension is given, the perl interpreter is used by default. If you don’t give the filename extension of .pl,
then to run the same program, you will have to give the command as follows:
C:perlscripts>perl hello
This will run the program as well.
In general, it’s a good idea to give your Perl programs the extension of .pl
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com
2. P age |2
Comments in Perl programs:
All comments begin with the # character. Comments can appear at the end of a Perl statement, like this:
print "Hello World.n"; #this is a greeting
There are no block comments in Perl
Analysis of the first program:
The very first line is #!/usr/bin/perl
On Unix systems, if the first two characters on the first line of a text file are #!, what follows is the anme of
the program that actually executes the rest of the file; in this case the file that is used is perl stored in bin
folder.
On Windows-based system, this first line can also be written as
#! perl
This gives the information that it’s a perl program. But this line is optional under Windows, if you have done
the default installation. The installation also sets the Path under Windows OS, so Windows knows where to
find the interpreter perl.exe.
How does my program run under Perl?
When you run your program, Perl’s internal compiler first runs through the entire source code, and
converts it into an internal bytecode.
After that, Perl’s bytecode engine takes over and actually runs the bytecode. If there’s a syntax error on a
line, say line 10, you’ll get that error message.
Prof. Mukesh N Tekwani mukeshtekwani@hotmail.com