Perl Tutorials
Using WWW-Mechanize
Perl Basics

Perl Basics

Basic Syntax


In perl all statements end with ';'. It is customary to start all scripts with '#!' followed by the path to the perl binary, this is required for a script to be executable directly. The #! is called a shebang. The shebang is a special shell symbol that tells the shell where to find the application used to execute the script.

Hello world


#!/usr/bin/perl
print "Hello worldn";

This is your basic hello world script. This script simply prints Hello world and exits. The n is the newline character. The location of the perl binary specified by the shebang may vary depending on your environment.

Variables

All variables start with a $. Perl variables are not type specific.

Setting values

$variable = 'value';

Scratch Variable

The perl scratch variable is a builtin that can be used as a shortcut. The scratch variable is accessed through the variable '$_'. The scratch variable is commonly set by not declaring a return value for a function call.

Math

+ -- addition
- -- subtraction
* -- multiplication
/ -- division

$add = 1 + 1;
print $add;
$sub = 2 - 1;
print $sub;
$mult = 3 * 4;
print $mult;
$div = 4 / 2;
print $div;

Grouping

Parenthesis are used to perform groupings and orgering of math expressions.

((1 + 1) * 2) + 3 = 7

 1 2 3 4 5  >> Arrays and Hashes in Perl
New Content

Related Information
Using WWW-Mechanize