First page Back Continue Last page Overview Graphics
Recursive Patterns
With the (?1) notation things are a little easier.
- if ('(x(x)y(x)x)'=~m/^(\((?>[^()]++|(?1))*\))$/x)
- { ... }
Advantages:
- Faster – Perl interpreter is not involved. Since pattern may not change the engine can optimize the pattern.
- Smaller – pattern need not be duplicated
- Self contained –no global vars
- Self describing – pattern is self contained. Context is not required to see what the pattern matches.