re
This pragma controls the use of regular expressions. It has five possible invocations:
taint; eval and /flags mode, which are lexically scoped; and
debug and debugcolor, which aren’t.
use re "taint";
# Contents of $match are tainted if $dirty was also tainted
($match) = ($dirty =~ /^(.*)$/s);
# Allow code interpolation:
use re "eval";
$pat = '(?{ $var = 1 })'; # embedded code execution
/alpha${pat}omega/; # won't fail unless under –T
# and $pat is tainted
use re "/a"; # by default, every pattern
# has the /a flag
use re "/msx"; # by default, every pattern
# has the /msx flags
use re "debug"; # like "perl –Dr"
/^(.*)$/s; # output debugging info during
# compile time and runtime
use re "debugcolor"; # same as "debug",
# but with colored output
use re qw(Debug LIST); # fine control of debugging outputWhen use re "taint" is in effect
and a tainted string is the target of a regex, the numbered regex
variables and values returned by the m// operator in list context are all tainted.
This is useful when regex operations on tainted data aren’t meant to
extract safe substrings, but are meant to do other transformations
instead. See the discussion on tainting in Chapter 20.
When use re "eval" is in effect,
a regex is allowed to contain assertions that execute Perl code, which are
of the form (?{ ... }), even when the regex contains interpolated variables. Execution of code segments resulting from variable interpolation into a regex is normally disallowed for security reasons: you don’t want ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access