X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlre.pod;h=f0d76453531a025bf62933411f199c66ea71f096;hb=27bcc0a7e6b15b7b0d6f632d5f31918abd005ef4;hp=a11e3e833b502679816699c0a78c1f996957d99e;hpb=f02c194e1a40f11d020685cd18b41e5261091b12;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlre.pod b/pod/perlre.pod index a11e3e8..f0d7645 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -195,7 +195,7 @@ as endpoints of a range, that's not a range, the "-" is understood literally. If Unicode is in effect, C<\s> matches also "\x{85}", "\x{2028}, and "\x{2029}", see L for more details about C<\pP>, C<\PP>, and C<\X>, and L about Unicode in general. -You can define your own C<\p> and C<\P> propreties, see L. +You can define your own C<\p> and C<\P> properties, see L. The POSIX character class syntax @@ -394,11 +394,15 @@ the most-recently closed group (submatch). C<$^N> can be used in extended patterns (see below), for example to assign a submatch to a variable. -The numbered variables ($1, $2, $3, etc.) and the related punctuation +The numbered match variables ($1, $2, $3, etc.) and the related punctuation set (C<$+>, C<$&>, C<$`>, C<$'>, and C<$^N>) are all dynamically scoped until the end of the enclosing block or until the next successful match, whichever comes first. (See L.) +B: failed matches in Perl do not reset the match variables, +which makes easier to write code that tests for a series of more +specific cases and remembers the best match. + B: Once Perl sees that you need one of C<$&>, C<$`>, or C<$'> anywhere in the program, it has to provide them for every pattern match. This may substantially slow your program. Perl @@ -570,6 +574,10 @@ track of the number of nested parentheses. For example: /the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i; print "color = $color, animal = $animal\n"; +Inside the C<(?{...})> block, C<$_> refers to the string the regular +expression is matching against. You can also use C to know what is +the current position of matching within this string. + The C is properly scoped in the following sense: If the assertion is backtracked (compare L<"Backtracking">), all changes introduced after Cization are undone, so that @@ -1274,7 +1282,7 @@ this: sub invalid { die "/$_[0]/: invalid escape '\\$_[1]'"} - my %rules = ( '\\' => '\\', + my %rules = ( '\\' => '\\\\', 'Y|' => qr/(?=\S)(?