Perl Tutorials
Using WWW-Mechanize
Perl Basics

Perl Basics

Arrays and hashes

Arrays

In Perl arrays start with @. When accessing an element of an array access like a variable (with $).

Defining values


@array = ("value1", "value2");
@array = (1, 2, 3);

push

Adds a value onto the end of an array.


push(@array, 4);

pop

Pulls the last variable off the end of an array. When you pop a value out of an array it is removed from the array


$val = pop(@array);

shift

Returns the first value of an array and collapses the rest of the values down.


$s = shift(@array);

[HEADERC:]unshift

inserts a value at the beginning of an array


unshift(@array, 'value');[:BR:

splice

Splicing an array will remove selected evelments of an array and optionally replace them another list.

Removing COUNT values starting at offset


splice(@array,OFFSET,COUNT)

Removing COUNT values starting at offset and replacing them with LIST


splice(@array,OFFSET,COUNT)
splice(@array,OFFSET,COUNT,LIST)

Hashes

Hashes are similar to arrays, but instead of numerical indexes hashes have scalar indexes called keys.

defining values


$hash{'key'} = 'value';

removing elements


delete($hash{'key'});

Basic Perl Syntax, Variables, and Math <<  1 2 3 4 5  >> Perl Conditionals
New Content

Related Information
Using WWW-Mechanize