Skip to Content
Intermediate Perl
book

Intermediate Perl

by Randal L. Schwartz, brian d foy, Tom Phoenix
March 2006
Intermediate to advanced
278 pages
6h 49m
English
O'Reilly Media, Inc.
Content preview from Intermediate Perl

Chapter 2. Intermediate Foundations

Before we get started on the meat of the book, we want to introduce some intermediate-level Perl idioms that we use throughout the book. These are the things that typically set apart the beginning and intermediate Perl programmers. Along the way, we’ll also introduce you to the cast of characters that we’ll use in the examples throughout the book.

List Operators

You already know about several list operators in Perl, but you may not have thought of them as working with lists. The most common list operator is probably print. We give it one or more arguments, and it puts them together for us.

print 'Two castaways are ', 'Gilligan', ' and ', 'Skipper', "\n";

There are several other list operators that you already know about from Learning Perl. The sort operator puts its input list in order. In their theme song, the castaways don’t come in alphabetical order, but sort can fix that for us.

my @castaways = sort qw(Gilligan Skipper Ginger Professor Mary-Ann);

The reverse operator returns a list in the opposite order.

my @castaways = reverse qw(Gilligan Skipper Ginger Professor Mary-Ann);

Perl has many other operators that work with lists, and, once you get used to them, you’ll find yourself typing less and expressing your intent more clearly.

List Filtering with grep

The grep operator takes a list of values and a “testing expression.” It takes one item after another in the list and places it into the $_ variable. It then evaluates the testing expression ...

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 Debugged

Perl Debugged

Peter Scott, Ed Wright
Think Perl 6

Think Perl 6

Laurent Rosenfeld, Allen B. Downey
Beginning Perl

Beginning Perl

Curtis Ovid Poe
Pro Perl

Pro Perl

Peter Wainwright

Publisher Resources

ISBN: 0596102062Supplemental ContentErrata Page