This document is intended to give you a quick overview of the Perl programming language as of Version 6,
along with pointers to further documentation.
It is intended as a "bootstrap" guide for those who are new to the language,
and provides just enough information for you to be able to read other peoples' Perl and understand roughly what it's doing,
or write your own simple scripts.

This introductory document does not aim to be complete.
It does not even aim to be entirely accurate.
In some cases perfection has been sacrificed in the goal of getting the general idea across.
You are strongly advised to follow this introduction with more information from the full Perl manual,
the table of contents to which can be found in perltoc.

Throughout this document you'll see references to other parts of the Perl documentation.
You can read that documentation using the p6doc command or whatever method you're using to read this document.

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.

The language is intended to be practical (easy to use,
efficient,
complete) rather than beautiful (tiny,
elegant,
minimal).
Its major features are that it's easy to use,
supports procedural,
object-oriented (OO) and a bit of functional programming,
and has powerful built-in support for text processing.
It can also use the large collection of Perl 5 modules.

A Perl script or program consists of one or more statements.
These statements are simply written in the script in a straightforward fashion.
There is no need to have a "main()" function or anything of that kind.

Perl statements end in a semi-colon:

say "Hello,
world";

Comments start with a hash symbol and run to the end of the line.
You can also have comments that are in the middle of a line by enclosing the comment with brackets.
You can have no space between the bracket and the hash:

# This is a comment say #(this is a comment too) "Hello World";

Whitespace is irrelevant,
for the most part.
However,
there are some places where space is required or not allowed:

say "Hello,
world" ; # this works "foo" .say; # this is a syntax error,
no space allowed.
"foo"\ .say; # this is a "long dot",
allowed.
backslashed whitespace is ignored.

...
except inside quoted strings:

# this would print with a linebreak in the middle say "Hello world";

Double quotes or single quotes may be used around literal strings:

say "Hello,
world"; say 'Hello,
world';

However,
only double quotes "interpolate" variables and special characters such as newlines ("\n"):

Scalar values can be strings,
integers or floating point numbers,
and Perl will automatically convert between them as required.
There is no need to pre-declare your variable types.
But if you feel like,
you declare their type explictly:

There are some "magic" scalars with names that look like punctuation or line noise.
These special variables are used for different purposes,
all of them are documented in doc:perlvar.
The only one you need to know about for now is $_ which is the "default variable".
It's used as the default argument to a number of functions if they start with a period . and it's set implicitly by certain looping constructs.

You might be tempted to use @array.end + 1 to tell you how many items there are in an array.
Don't bother.
As it happens,
using @array where Perl expects to find a scalar value ("in scalar context") will give you the number of elements in the array:

if @animals < 5 { ...
}

If you want to get the number of elements explicitly,
you can use elems:

print @animals.elems # prints "3";

To get multiple elements from an you can use a list of indexes in the square brackets:

You can use whitespace and the "=>" operator to lay them out more nicely:

my %fruit_color = "apple" = "red",
"banana" => "yellow",
); >

To get at hash elements:

%fruit_color{"apple"}; # gives "red"

You can get a list of keys and values with the keys and values methods:

my @fruits = %fruit_color.keys; my @colors = %fruit_color.values;

Hashes have no particular internal order,
though you can sort the keys and loop through them.

Just like special scalars and arrays,
there are also special hashes.
The most well known of these is %*ENV which contains environment variables.
Read all about it (and other special variables) in doc:perlvar.

Perl comes with a wide selection of builtin functions. Some of the ones we've already seen include say, sort and reverse. A list of them is given at the start of perlfunc and you can easily read about any given function by using "p6doc -f functionname".