XML technologies / Regular expressions / Perl / Perl concepts for regular expressions

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

Certain topics and concepts in Perl are especially important for regular expressions. The next sections discuss:

 

Context

A central Perl concept is that many operators and functions adapt to their context . For example, Perl expects a scalar value in the condition of a while (loop), but a list as the argument of a print statement. Since an expression can adapt to context in Perl, the same expression may produce very different results in different contexts.

 

Dynamic scope

Most programming languages have local and global variables, but Perl has a third kind: variables with dynamic scope or dynamic scoping. A dynamically created variable temporarily masks a corresponding global variable. Its old value is saved and automatically restored when the dynamic scope ends. This feature affects regular expressions because it can influence the scope of $1 and other side effects.

  

  

 

 

 

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