This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
merge changes#1210,1211,1270 from maintbranch
[perl5.git] / lib / re.pm
CommitLineData
b3eb6a9b
GS
1package re;
2
3=head1 NAME
4
5re - Perl pragma to alter regular expression behaviour
6
7=head1 SYNOPSIS
8
9 ($x) = ($^X =~ /^(.*)$/s); # $x is not tainted here
10
11 use re "taint";
12 ($x) = ($^X =~ /^(.*)$/s); # $x _is_ tainted here
13
14=head1 DESCRIPTION
15
16When C<use re 'taint'> is in effect, and a tainted string is the target
17of a regex, the regex memories (or values returned by the m// operator
18in list context) are tainted.
19
20This feature is useful when regex operations on tainted data aren't
21meant to extract safe substrings, but to perform other transformations.
22
23See L<perlmodlib/Pragmatic Modules>.
24
25=cut
26
27my %bitmask = (
28taint => 0x00001000
29);
30
31sub bits {
32 my $bits = 0;
33 unless(@_) {
34 require Carp;
35 Carp::carp("Useless use of \"re\" pragma");
36 }
37 foreach my $s (@_){ $bits |= $bitmask{$s} || 0; };
38 $bits;
39}
40
41sub import {
42 shift;
43 $^H |= bits(@_);
44}
45
46sub unimport {
47 shift;
48 $^H &= ~ bits(@_);
49}
50
511;