< Free Open Study > |
7.1 Regular Expressions as a Language ComponentAn attractive feature of Perl is that regex support is so deftly built in as part of the language. Rather than providing stand-alone functions for applying regular expressions, Perl provides regular-expression operators that are meshed well with the rich set of other operators and constructs that make up the Perl language. With as much regex-wielding power as Perl has, one might think that it's over- flowing with different operators and such, but actually, Perl provides only four regex-related operators, and a small handful of related items, shown in Table 7-1.
Perl is extremely powerful, but all that power in such a small set of operators can be a dual-edged sword. 7.1.1 Perl's Greatest StrengthThe richness of variety and options among Perl's operators and functions is perhaps its greatest feature. They can change their behavior depending on the context in which they're used, often doing just what the author naturally intends in each differing situation. In fact, O'Reilly's Programming Perl goes so far as to boldly state "In general, Perl operators do exactly what you want...." The regex match operator m/ regex /, for example, offers an amazing variety of different functionality depending upon where, how, and with which modifiers it is used. 7.1.2 Perl's Greatest WeaknessThis concentrated richness in expressive power is also one of Perl's least-attractive features. There are innumerable special cases, conditions, and contexts that seem to change out from under you without warning when you make a subtle change in your code—you've just hit another special case you weren't aware of.[2] The Programming Perl quote in the previous paragraph continues "...unless you want consistency." Certainly, when it comes to computer science, there is a certain appreciation to boring, consistent, dependable interfaces. Perl's power can be a devastating weapon in the hands of a skilled user, but it sometimes seems with Perl, you become skilled by repeatedly shooting yourself in the foot.
|
< Free Open Study > |