Perl Programming/Variables

In Perl, there are five types of variables: $calars, @rrays, %hashes, &subroutines, and *typeglobs.

Simple variables
Variables, called scalars, are identified with the $ character, and can contain nearly any type of data. For example:

Case sensitivity
Note that the perl interpreter is case sensitive. This means that identifier names containing lowercase letters will be treated as being different and separate from those containing uppercase letters.

Arrays
Arrays in Perl use the @ character to identify themselves.

However, when you deal with just one element of the array (using square brackets so it's not confused), then that element of the array is considered a scalar which takes the $ sigil:

As in the C programming language, the number of the first element is 0 (although as with all things in Perl, it's possible to change this if you want). Array subscripts can also use variables:

Associative arrays
Associative arrays, or "hashes," use the % character to identify themselves.

When using the =&gt; the left side is assumed to be quoted. For long lists, lining up keys and values aids readability.

However, when you deal with just one element of the array (using braces), then that element of the array is considered a scalar and takes the $ identifier:

Associative arrays are useful when you want to refer to the items by their names.

Subroutines
Subroutines are defined by the sub function, and used to be called using & (using  is now deprecated). Here's an example program that calculates the Fibonnaci sequence: