/foo${pat}bar/; # disallowed (with or without -T switch)
}
- use re 'debug';
- /^(.*)$/s; # output debugging info
- # during compile and run time
+ use re 'debug'; # NOT lexically scoped (as others are)
+ /^(.*)$/s; # output debugging info during
+ # compile and run time
(We use $^X in these examples because it's tainted by default.)
expression is obtained from tainted data, i.e. evaluation is always
disallowed with tainted regular expresssions. See L<perlre/(?{ code })>.
-For the purpose of this pragma, interpolation of preexisting regular
-expressions is I<not> considered a variable interpolation, thus
+For the purpose of this pragma, interpolation of precompiled regular
+expressions (i.e., the result of C<qr//>) is I<not> considered variable
+interpolation. Thus:
/foo${pat}bar/
-I<is> allowed if $pat is a preexisting regular expressions, even
+I<is> allowed if $pat is a precompiled regular expression, even
if $pat contains C<(?{ ... })> assertions.
When C<use re 'debug'> is in effect, perl emits debugging messages when
of the match.
See L<perldebug/"Debugging regular expressions"> for additional info.
-I<The directive C<use re 'debug'> is not lexically scoped.> It has
-both compile-time and run-time effects.
+The directive C<use re 'debug'> is I<not lexically scoped>, as the
+other directives are. It has both compile-time and run-time effects.
See L<perlmodlib/Pragmatic Modules>.
=head2 New C<qr//> operator
The C<qr//> operator, which is syntactically similar to the other quote-like
-operators, is used to create compiled regular expressions. This compiled
+operators, is used to create precompiled regular expressions. This compiled
form can now be explicitly passed around in variables, and interpolated in
-other regular expressions. See L<perlop> and L<perlre>.
+other regular expressions. See L<perlop>.
=head2 C<our> is now a reserved word
regular expression. The result may be used as a pattern in a match
$re = qr/$pattern/;
- $string =~ /$re/;
+ $string =~ /foo${re}bar/; # can be interpolated in other patterns
+ $string =~ $re; # or used standalone
Options are:
s Treat string as single line.
x Use extended regular expressions.
-The benefit from this is that the pattern is compiled into an internal
-representation by the C<qr//> operator and not by the match operator.
+The benefit from this is that the pattern is precompiled into an internal
+representation, and does not need to be recompiled every time a match
+is attempted. This makes it very efficient to do something like:
foreach $pattern (@pattern_list) {
my $re = qr/$pattern/;
}
}
+See L<perlre> for additional information on valid syntax for STRING, and
+for a detailed look at the semantics of regular expressions.
+
=item qx/STRING/
=item `STRING`
This page describes the syntax of regular expressions in Perl. For a
description of how to I<use> regular expressions in matching
operations, plus various examples of the same, see discussion
-of C<m//>, C<s///>, and C<??> in L<perlop/Regexp Quote-Like Operators>.
+of C<m//>, C<s///>, C<qr//> and C<??> in L<perlop/Regexp Quote-Like Operators>.
The matching operations can have various modifiers. The modifiers
that relate to the interpretation of the regular expression inside