Picking Up Perl by Kuhn B. M.

By Kuhn B. M.

Show description

Read Online or Download Picking Up Perl PDF

Similar programming: programming languages books

Extra info for Picking Up Perl

Example text

The ()’s are used for grouping. For example, if we want to match any string that contains abc or def, zero or more times, surrounded by a xx on either side, we could write the regular expression xx(abc|def)*xx. This applies the * character to everything that is in the parentheses. Thus we can match any strings such as xxabcxx, xxabcdefxx, etc. 6 The Anchor Characters Sometimes, we want to apply the regular expression from a defined point. In other words, we want to anchor the regular expression so it is not permitted to match anywhere in the string, just from a certain point.

If we applied this to our last regular expression, we have ^aa*$ which now matches only those strings that consist of one or more a’s. This makes it clear that the regular expression cannot just look anywhere in the string, rather the regular expression must be able to match the entire string exactly, or it will not match at all. In most cases, you will want to either anchor a regular expression to the start of the string, the end of the string, or both. Using a regular expression without some sort of anchor can also produce confusing and strange results.

Before Perl, almost all text processing on Unix-like systems was done with a conglomeration of tools that included AWK, ‘sed’, the various shell programming languages, and C programs. Larry wanted to fill the void between “manipulexity” (the ability of languages like C to “get into the innards of things”) and “whipuptitude” (the property of programming languages like AWK or ‘sh’ that allows programmers to quickly write useful programs). Thus, Perl, the Practical Extraction and Report Language1 , was born.

Download PDF sample

Rated 4.64 of 5 – based on 4 votes