Skip to Main Content
Perl Pocket Reference, 5th Edition
book

Perl Pocket Reference, 5th Edition

by Johan Vromans
July 2011
Intermediate to advanced content levelIntermediate to advanced
104 pages
2h 14m
English
O'Reilly Media, Inc.
Content preview from Perl Pocket Reference, 5th Edition

Variables

$var

A simple scalar variable.

$p = \$var

Now $p is a reference to scalar $var.

$$p

The scalar referenced by $p.

@var

An array. In scalar context, the number of elements in the array.

$var[6]

Seventh element of array @var.

$var[-1]

The last element of array @var.

$p = \@var

Now $p is a reference to array @var.

$$p[6] or $p->[6]

Seventh element of array referenced by $p.

${$p[6]}

The scalar referenced by $p[6].

$p = \$var[6]

Now $p is a reference to the seventh element of array @var.

$p = [1,3,'ape']

Now $p is a reference to an anonymous array with three elements.

$var[$i][$j]

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

$#var

Last index of array @var.

@var[3,4,5]

A slice of array @var.

%var

A hash. In scalar context, true if the hash has elements.

$var{'red'} or $var{red}

A value from hash %var. The hash key may be specified without quotes if it is simple identifier.

$p = \%var

Now $p is a reference to hash %var.

$$p{'red'} or $p->{'red'}

A value from the hash referenced by $p.

${$p{'red'}}

The scalar referenced by $p{'red'}.

$p = {red => 1, blue => 2, yellow => 3}

Now $p is a reference to an anonymous hash with three elements.

@var{'a','b'}

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

$var{'a'}[1]

Multidimensional hash.

$var{'a',1, ... }

Emulated multidimensional hash (obsolete).

$c = \&mysub

Now $c is a reference to subroutine mysub.

$c = sub { . . . }

Now $c is a reference to an anonymous subroutine.

&$c( args ) or $c->( args )

A call to the subroutine via the reference.

$MyPackage::var

Variable $var from package ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Perl Testing: A Developer's Notebook

Perl Testing: A Developer's Notebook

Ian Langworth, Chromatic
Perl Hacks

Perl Hacks

Chromatic, Damian Conway, Curtis Ovid Poe, Curtis (Ovid) Poe

Publisher Resources

ISBN: 9781449311186Errata Page