User Tools

Site Tools


My first Perl program


Perl stands for Practical Extraction and Report Language. It is created and developed by Larry Wall. The Perl language specialized in string manipulation, system tasks and Input/Output. Perl is an interpreted language. That means that there is no need of compiler when writing Perl programs, you only need a perl language interpreter. You don't create binaries from a Perl source, you use to Perl script source to interpret it and run it. On almost all *nix systems the perl interpreter binary is called “perl”. The big breakout of Perl was with the explosion of the WWW (World Wide Web) service. The Perl scripts were found as a fast, reliable and effective way of using applications which requre server interaction. Because of the simplicity and the usability of the Perl language a lot of system administrators use it actively.

The Hello World program

We continue with our tradition:

print "Hello World\n";

This seems as an awfully easy code to write. Unlike the C and C++ languages, Perl codes are scripts, they don't have to contain main() function, or any other function at all. However, let's explain this simple code. Notice the first line: #!/usr/local/bin/perl. This line informs the system what to do with the perl script when it is runned. In this example, it tells to the system to run it through the perl interpreter, located in the /usr/local/bin directory. This line may vary from system to system.


All commented lines in Perl start with the '#' sign. Everything after that sign is ignored.

#This is comment
#This is ignored

print "Test\n";


There is Output stream in Perl as well. It is a byte stream which by default is directed to STDOUT. Actually, the line:

print "Hello World\n";

is a short form from:

print STDOUT "Hello World\n";

If you use single quotes (') instead of double quites (“), print will print everything literally. For example, the output of:

print 'Hello World\n';

will be:

Hello World\n

We will talk more about printing later.


You can easily access STDIN, the Standard Input, in Perl scripts:

#Input script

$input = ;
print $input;

STDIN usually comes from the keyboard, but , just like STDOUT, it is just a file handle. We will discuss variables, like $input here, later in the document.

handbook/handbook/perl1.txt · Last modified: 2010/04/15 21:18 (external edit)