Skip to Main Content
Programming Perl, 3rd Edition
book

Programming Perl, 3rd Edition

by Larry Wall, Tom Christiansen, Jon Orwant
July 2000
Intermediate to advanced content levelIntermediate to advanced
1104 pages
35h 1m
English
O'Reilly Media, Inc.
Content preview from Programming Perl, 3rd Edition

The Arrow Operator

Just as in C and C++, the binary -> operator is an infix dereference operator. If the right side is a […] array subscript, a {…} hash subscript, or a (…) subroutine argument list, the left side must be a reference (either hard or symbolic) to an array, a hash, or a subroutine, respectively. In an lvalue (assignable) context, if the left side is not a reference, it must be a location capable of holding a hard reference, in which case such a reference will be autovivified for you. For more on this (and some warnings about accidental autovivification) see Chapter 8.

$aref->[42]               # an array dereference
$href->{"corned beef"}    # a hash dereference
$sref->(1,2,3)            # a subroutine dereference

Otherwise, it's a method call of some kind. The right side must be a method name (or a simple scalar variable containing the method name), and the left side must evaluate to either an object (a blessed reference) or a class name (that is, a package name):

$yogi = Bear->new("Yogi");    # a class method call
$yogi->swipe($picnic);        # an object method call

The method name may be qualified with a package name to indicate in which class to start searching for the method, or with the special package name, SUPER::, to indicate that the search should start in the parent class. See Chapter 12.

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

Mastering Perl, 2nd Edition

Mastering Perl, 2nd Edition

brian d foy
Programming the Perl DBI

Programming the Perl DBI

Tim Bunce, Alligator Descartes
Perl in a Nutshell, 2nd Edition

Perl in a Nutshell, 2nd Edition

Nathan Patwardhan, Ellen Siever, Stephen Spainhour

Publisher Resources

ISBN: 0596000278Supplemental ContentErrata