Professional Documents
Culture Documents
T1
PERL BASICS
What is PERL ?
The name Perl comes from Practical Extraction and Report Language.
Perl has many features borrowed from other programming languages.
The Perl system uses an interpreter, called perl.
Perl is a general-purpose programming language originally developed for
text manipulation and now used for a wide range of tasks including
system administration, web development, network programming, GUI
development, and more.
Pros and Cons of PERL
PROS
Perl is built around regular expressions
What is a REGULAR EXPRESSION ??
REs are good for string processing
Therefore Perl is a good scripting language
Perl makes full use of the power of UNIX
Short Perl programs can be very short
Perl is designed to make the easy jobs easy, without making the difficult jobs impossible.
-- Larry Wall, Programming Perl
CONS
Perl is very UNIX-oriented
Perl is available on other platforms...
...but isnt always fully implemented there
However, Perl is often the best way to get some UNIX capabilities on less capable platforms
Perl does not scale well to large programs
Weak subroutines, heavy use of global variables
Perls syntax is not particularly appealing
Finding PERL in your system
You can easily check whether Perl is loaded on your system by opening a
console or terminal window and issuing the command:
perl v
If you get a version number, Perl is installed. If you get an error
message about command not found (or something similar), Perl is not
installed.
For example in our systems:
PERL Documentation
Every release of Perl comes with documentation in a set of files. Most releases have over
1,700 pages of documentation included in reference books, user guides, FAQs, and so on.
On most operating systems, a utility called perldoc is installed as part of the Perl
system. The perldoc utility can search for and format Perl documentation for you. To use
perldoc to look up the basic syntax for perl, open a terminal or console and issue the
command:
perldoc perl
The Perl documentation is divided into parts by purpose:
perlfunc (Perl functions)
perlfaq (Perl FAQs)
perlop (Perl operators)
To search for a particular keyword, use the tf options. For example to look up the print
keyword:
perldoc tf print
To search the FAQs use q as an option:
perldoc q free
Perl Documentation Website : https://perldoc.perl.org
Point to Note
Comments are # to end of line
The first line, #!/usr/local/bin/perl, tells where to find the Perl compiler on your system
Perl statements end with semicolons
Perl is case-sensitive
Perl is compiled and run in a single operation
The -w switch tells perl to produce extra warning messages about potentially dangerous constructs.
You can use unix commands by using System("unix command");
E.g, system("ls *");
Will give the directory listing on the terminal where it is running.
Executing PERL Scripts
Interactive Mode Programming:
You can use Perl interpreter with -e option at command line which lets you execute Perl
statements from the command line. Let's try something at $ prompt as follows:
$perl -e 'print "Hello World\n"'
This execution will produce following result:
Hello, world
You can use parentheses for functions arguments or omit them according to your personal taste.
They are only required occasionally to clarify issues of precedence. Following two statements
produce same result.
print("Hello, world\n");
print "Hello, world\n";
Change the mode of the script file and give execution privilege.