Skip to Content
Perl Pocket Reference, 4th Edition
book

Perl Pocket Reference, 4th Edition

by Johan Vromans
July 2002
Beginner to intermediate
96 pages
1h 53m
English
O'Reilly Media, Inc.
Content preview from Perl Pocket Reference, 4th Edition

Chapter 8. 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 (obsolete).

$c = \&mysub

Now $c is a reference to subroutine mysub.

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

A call to the subroutine via the reference.

$c = sub { ... }

Now $c is a reference to an anonymous subroutine.

pkg::var

A variable from a package, e.g., $pkg::var, @pkg::ary. The default 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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Perl Pocket Reference, 5th Edition

Perl Pocket Reference, 5th Edition

Johan Vromans
Perl Debugged

Perl Debugged

Peter Scott, Ed Wright
Intermediate Perl, 2nd Edition

Intermediate Perl, 2nd Edition

Randal L. Schwartz, brian d foy, Tom Phoenix
Mastering Perl

Mastering Perl

brian d foy

Publisher Resources

ISBN: 9780596806354Errata Page