XML technologies / Regular expressions / Perl

(Excerpt from "Regular expressions" by Jeffrey E. F. Friedl)

Perl appears throughout this book for good reasons. It is widespread, offers a rich regex language, is free and readily available, welcomes beginners, and runs on many platforms, including Windows, Unix, and MacOS.

Some syntax resembles C or other traditional languages, but similarities end there. Perl’s approach to solving problems, The Perl Way, differs greatly from traditional approaches. A script’s broad structure often resembles structured or object-oriented programs, but actual data processing relies heavily on regexes. Regexes play a crucial role in almost every Perl program, I think it is fair to say. This holds for huge packages with tens of thousands of lines as well as a one-liner such as

% perl -pi -e 's{([-+]?\d+(\.\d*)?)F\b}{sprintf "%.0fC", ($1-32)*5/9}eg' *.txt

that replaces Fahrenheit temperatures in *.txt files with Celsius, recalling the first example from Extended introductory examples.

In this chapter

This chapter covers Perl’s regex-related features, using version 5.8.8: its dialect and regex operators. Regex matters are explained from the ground up, but some general Perl familiarity is assumed. Working through Extended introductory examples may initially suffice. Some points are only mentioned briefly, and unrelated language features are barely explained. Keep Perl’s documentation or the book Programmieren mit Perl from O’Reilly handy.

Perhaps more important than prior Perl knowledge is a desire to learn more about Perl. This chapter is demanding. I am not writing a Perl textbook, so I can focus on interesting subjects without building a coherent course or excluding topics too hard for beginners. The common thread is deep understanding. Some topics are intricate and may not be immediately clear. Read the chapter once for the overall picture, then use it as a reference.

This preview clarifies the chapter’s structure:

Perl in earlier chapters

Perl is used or mentioned throughout most of this book:

Earlier Perl examples were often deliberately simple, keeping the main point clear and helping readers unfamiliar with Perl. This chapter’s examples use idiomatic Perl.

  

  

 

 

 

German edition copyright © 2008 by O’Reilly Verlag GmbH & Co. KG
You may print the online version for private use.
Otherwise, this chapter from "Reguläre Ausdrücke" is subject to the same terms as the bound edition: the work and all its parts are protected by copyright. All rights reserved, including reproduction, translation, microfilming, storage and processing in electronic systems.

O’Reilly Verlag GmbH & Co. KG, Balthasarstr. 81, 50670 Köln

back to top