Chapter 17. Some Advanced Perl Techniques

What you’ve seen so far is the core of Perl, the part that you as a Perl user should understand. But there are many other techniques that, while not obligatory, are still valuable tools to have in your toolbox. We’ve gathered the most important of those for this chapter. This also segues into the continuation of this book, Intermediate Perl, which is your next step in Perl.

Don’t be misled by the title of the chapter, though; the techniques here aren’t especially more difficult to understand than those that you’ve already seen. They are “advanced” merely in the sense that they aren’t necessary for beginners. The first time you read this book, you may want to skip (or skim) this chapter so you can get right to using Perl. Come back to it a month or two later, when you’re ready to get even more out of Perl. Consider this entire chapter a huge footnote.[388]

Slices

It often happens that you need to work with only a few elements from a given list. For example, the Bedrock Library keeps information about their patrons in a large file.[389] Each line in the file describes one patron with six colon-separated fields: a person’s name, library card number, home address, home phone number, work phone number, and number of items currently checked out. A little bit of the file looks something like this:

fred flintstone:2168:301 Cobblestone Way:555-1212:555-2121:3
barney rubble:709918:3128 Granite Blvd:555-3333:555-3438:0

One of the library’s applications ...

Get Learning Perl, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.