Webmaster in a Nutshell

Previous Chapter 15
Perl Quick Reference

15.3 Variables


A simple scalar variable.


29th element of array @var.

$p = \@var

Now $p is a reference to array @var.


29th element of array referenced by $p.

Also, $p->[28].


Last element of array @var.


$j-th element of $i-th element of array @var.


A value from hash (associative array) %var.

$p = \%var

Now $p is a reference to hash %var.


A value from hash referenced by $p.

Also, $p->{'Feb'}.


Last index of array @var.


The entire array; in a scalar context, the number of elements in the array.


A slice of array @var.


A slice of %var; same as ($var{'a'},$var{'b'}).


The entire hash; in a scalar context, true if the hash has elements.


Emulates a multidimensional array.


A slice of an array literal.


A variable from a package, e.g., $pkg::var, @pkg::ary.


Reference to an object, e.g., \$var, \%hash.


Refers to all objects represented by name.

*n1 = *n2 makes n1 an alias for n2.

*n1 = $n2 makes $n1 an alias for $n2.

You can always use a { block } returning the right type of reference instead of the variable identifier, e.g., ${...}, &{...}. $$p is just a shorthand for ${$p}.

Previous Home Next
Literals Book Index Operators

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell
Hosted by uCoz