Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 11. REGULAR EXPRESSION GRAPHER - Pg. 183

183 Chapter 11. REGULAR EXPRESSION GRAPHER Regular expressions are among Perl's most powerful features. But they are also the most cryptic. After all, it's hard at first glance to tell what /\s*(\S+)(\d+)/ really means. But it turns out that the regular expression matcher is a simple state machine whose input and processing can easily be represented graphically, as shown. Figure 11-1. From this you can see that the regular expression consists of three major parts (excluding the start and end nodes) and that it stores results into $1 and $2. We'll go into what all those lines and symbols mean later, but this example shows how something complex and cryptic can be made simple and understandable if you present it in the right manner. #44 Regular Expression Parser In order to be able to graph a regular expression, you first must figure out what's in it. That's the job of the parse.pm module. The Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 # # parse_re -- Parse a regular expression # use strict; use warnings; package parse; require Exporter; use English; use vars qw/@ISA @EXPORT/; @ISA = qw/Exporter/;