You are on page 1of 2

jj

Perl Programming

Basics Variables and Operators Branching Looping File Test Operators Regular Expressions Input and Output Processing files mentioned on the Commandline Get Filenames Pipe input and ouput from/to Unix Commands Execute Unix Commands The Perl builtin Functions Subroutines Some of the special Variables Forking Building Pipes for forked Children Building a Socket Connectin to another Computer Get User and Network Information Arithmetics Formatting Output with "format" Commandline Switches Full Perl 5 Documentation

Basics
Scripts
Perl is a script language, which is compiled each time before running. That unix knows that it is a perl script there must be the following header at the topline of every perl script: #!/usr/bin/perl where the path to perl has to be correct and the line must not exeed 32 charachters.

Comments and Commands


After the header line: #!/usr/bin/perl there are either empty lines with no effect or commandlines or commentary lines. Everything from and behind a " #" up to the end of the line is comment and has no effect on the program. Commands start with the first non space charachter on a line and end with a ";". So one can continue a command over several lines and terminates it only with the semicolon.

Direct commands and soubroutines


Normal commands are executed in the order written in the script. But soubroutines can be placed anywhere and will only be evaluated when called from a normal commandline. Perl knows it's a soubroutine if it the code is preceeded with a "sub" and enclosed in a block like: sub name { command;}

Other special lines


Perl can include other programming code with: require something or with use something.

Quotations
Single quote: '' or: q// Double quote: "" or: qq// Quote for execution: `` or: qx// Quote a list of words: ('term1','term2','term3') or: qw/term1 term2 term3/ Quote a quoted string: qq/"$name" is $name/; Quote something wich contains "/": qq!/usr/bin/$file is readdy!;

Scalar and list context


That perl distinguishes between scalar and list context is the big feature, which makes it uniqe and more usful then most other script languages. A soubroutine can return lists and not only scalars like in C. Or an array gives the number of elements in a scalar context and the elements itself in a list context. The enormous value of that feature should be evident.

You might also like