This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta: Give better instructions about (?^...)
[perl5.git] / pod / perldelta.pod
index acd1644..3ac058d 100644 (file)
@@ -1,26 +1,20 @@
 =encoding utf8
 
-=for release_engineer
-* changelogged up to a1bbdff
-* the mauve module will not be part of the release, so it's not changelogged
-yet. it also added some new api functions. those aren't covered either, as they
-might go away again in case mauve gets rolled back for 5.13.5.
-
 =head1 NAME
 
 [ this is a template for a new perldelta file. Any text flagged as
 XXX needs to be processed before release. ]
 
-perldelta - what is new for perl v5.13.5
+perldelta - what is new for perl v5.13.6
 
 =head1 DESCRIPTION
 
-This document describes differences between the 5.13.4 release and
-the 5.13.5 release.
+This document describes differences between the 5.13.5 release and
+the 5.13.6 release.
 
-If you are upgrading from an earlier release such as 5.13.3, first read
-L<perl5134delta>, which describes differences between 5.13.3 and
-5.13.4.
+If you are upgrading from an earlier release such as 5.13.4, first read
+L<perl5135delta>, which describes differences between 5.13.4 and
+5.13.5.
 
 =head1 Notice
 
@@ -32,42 +26,32 @@ XXX New core language features go here. Summarise user-visible core language
 enhancements. Particularly prominent performance optimisations could go
 here, but most should go in the L</Performance Enhancements> section.
 
-=head2 Adjacent pairs of nextstate opcodes are now optimized away
-
-Previously, in code such as
-
-    use constant DEBUG => 0;
-
-    sub GAK {
-        warn if DEBUG;
-        print "stuff\n";
-    }
+[ List each enhancement as a =head2 entry ]
 
-the ops for C<warn if DEBUG;> would be folded to a C<null> op (C<ex-const>), but
-the C<nextstate> op would remain, resulting in a runtime op dispatch of
-C<nextstate>, C<nextstate>, ...
+=head2  C<(?^...)> regex construct added to signify default modifiers
 
-The execution of a sequence of C<nexstate> ops is indistinguishable from just
-the last C<nextstate> op, so teach the peephole optimiser to eliminate the first
-of a pair of C<nextstate> ops. (Except where the first carries a label, as
-labels mustn't be eliminated by the optimiser, and label usage isn't
-conclusively known at compile time.)
+A caret (also called a "cirumflex accent") C<"^"> immediately following
+a C<"(?"> in a regular expression now means that the subexpression is to
+not inherit the surrounding modifiers such as C</i>, but to revert to the
+Perl defaults.  Any modifiers following the caret override the defaults.
 
-=head2 API function to parse statements
+The stringification of regular expressions now uses this notation.  The
+main purpose of this is to allow tests that rely on the stringification
+to not have to change when new modifiers are added.  See
+L<perlre/Extended Patterns>.
 
-The C<parse_fullstmt> function has been added to allow parsing of a single
-complete Perl statement. See L<perlapi> for details.
+=head2 C<"d">, C<"l">, and C<"u"> regex modifiers added
 
-=head2 API functions for accessing the runtime hinthash
+These modifiers are currently only available within a C<(?...)> construct.
 
-A new C API for introspecting the hinthash C<%^H> at runtime has been added. See
-C<cop_hints_2hv>, C<cop_hints_fetchpvn>, C<cop_hints_fetchpvs>, and
-C<cop_hints_fetchsv> in L<perlapi> for details.
+The C<"l"> modifier says to compile the regular expression as if it were
+in the scope of C<use locale>, even if it is not.
 
-=head2 C interface to C<caller()>
+The C<"u"> modifier currently does nothing.
 
-The C<caller_cx> function has been added as an XSUB-writer's equivalent of
-C<caller()>. See L<perlapi> for details.
+The C<"d"> modifier is used in the scope of C<use locale> to compile the
+regular expression as if it were not in that scope.
+See L<perlre/(?dlupimsx-imsx)>.
 
 =head1 Security
 
@@ -79,37 +63,45 @@ L</Selected Bug Fixes> section.
 
 =head1 Incompatible Changes
 
-=head2 Magic Variables Outside the Main Package
+=head2 Stringification of regexes has changed
 
-In previous versions of perl, magic variables like C<$!>, C<%SIG>, etc.  would
-'leak' into other packages. So C<%foo::SIG> could be used to access signals,
-C<${"foo::!"}> (with strict mode off) to access C's C<errno>, etc.
+Default regular expression modifiers are now notated by using
+C<(?^...)>.  Code relying on the old stringification will fail.  The
+purpose of this is so that when new modifiers are added, such code will
+not have to change (after this one time), as the stringification will
+automatically incorporate the new modifiers.
 
-This was a bug, or an 'unintentional' feature, which caused various ill
-effects, such as signal handlers being wiped when modules were loaded, etc.
+Code that needs to work properly with both old- and new-style regexes
+can avoid the whole issue by using:
 
-This has been fixed (or the feature has been removed, depending on how you
-see it).
+ use re qw(regexp_pattern);
+ my ($pat, $mods) = regexp_pattern($re_ref);
 
-=head2 Smart-matching against array slices
+where C<$re_ref> is a reference to a compiled regular expression.  Upon
+return, C<$mods> will be a string containing all the non-default
+modifiers used when the regular expression was compiled, and C<$pattern>
+the actual pattern.
 
-Previously, the following code resulted in a successful match:
+If the actual stringification is important, you can use something like
+the following:
 
-    my @a = qw(a y0 z);
-    my @b = qw(a x0 z);
-    $a[0 .. $#b] ~~ @b;
+    # Accept both old and new-style stringification
+    my $modifiers = (qr/foobar/ =~ /\Q(?^/) ? '^' : '-xism';
 
-This odd behaviour has now been fixed [perl #77468].
+And then use C<$modifiers> instead of C<-xism>.
 
-=head2 C API changes
+=head2 Regular expressions retain their localeness when interpolated
 
-The first argument of the C API function C<Perl_fetch_cop_label> has changed
-from C<struct refcounted he *> to C<COP *>, to better insulate the user from
-implementation details.
+Regular expressions compiled under C<"use locale"> now retain this when
+interpolated into a new regular expression compiled outside a
+C<"use locale">, and vice-versa.
 
-This API function was marked as "may change", and likely isn't in use outside
-the core. (Neither an unpacked CPAN, nor Google's codesearch, finds any other
-references to it.)
+Previously, a regular expression interpolated into another one inherited
+the localeness of the surrounding one, losing whatever state it
+originally had.  This is considered a bug fix, but may trip up code that
+has come to rely on the incorrect behavior.
+
+[ List each incompatible change as a =head2 entry ]
 
 =head1 Deprecations
 
@@ -117,18 +109,7 @@ XXX Any deprecated features, syntax, modules etc. should be listed here.
 In particular, deprecated modules should be listed here even if they are
 listed as an updated module in the L</Modules and Pragmata> section.
 
-=head2 Use of qw(...) as parentheses
-
-Historically the parser fooled itself into thinking that C<qw(...)> literals
-were always enclosed in parentheses, and as a result you could sometimes omit
-parentheses around them:
-
-    for $x qw(a b c) { ... }
-
-The parser no longer lies to itself in this way.  Wrap the list literal in
-parentheses, like:
-
-    for $x (qw(a b c)) { ... }
+[ List each deprecation as a =head2 entry ]
 
 =head1 Performance Enhancements
 
@@ -141,14 +122,7 @@ may well be none in a stable release.
 
 =item *
 
-Scalars containing regular expressions now only allocate the part of the C<SV>
-body they actually use, saving some space.
-
-=item *
-
-Compiling regular expressions has been made faster for the case where upgrading
-the regex to utf8 is necessary, but that isn't known when the compilation
-begins.
+XXX
 
 =back
 
@@ -180,98 +154,35 @@ XXX
 
 =item *
 
-C<blib> has been upgraded from version 1.05 to 1.06.
-
-=item *
+C<File::DosGlob> has been upgraded from version 1.02 to 1.03.
 
-C<bignum>, C<bigint>, and C<bigrat> have been upgraded from version 0.23 to
-0.25.
+It allows patterns containing literal parentheses (they no longer need to
+be escaped). On Windows, it no longer adds an extra F<./> to the file names
+returned when the pattern is a relative glob with a drive specification,
+like F<c:*.pl>.
 
 =item *
 
-C<open> has been upgraded from version 1.07 to 1.08.
+C<File::Find> has been upgraded from version 1.17 to 1.18.
 
-=item *
-
-C<warnings> has been upgraded from version 1.10 to 1.11.
-
-C<warnings::register> has been upgraded from version 1.01 to 1.02.
-
-It is now possible to register warning categories other than the names of
-packages using warnings::register.  See L<perllexwarn> for more information.
-
-=item *
-
-C<B::Debug> has been upgraded from version 1.12 to 1.14.
+It improves handling of backslashes on Windows, so that paths such as
+F<c:\dir\/file> are no longer generated.
 
 =item *
 
-C<Data::Dumper> has been upgraded from version 2.126 to 2.128.
-
-This fixes a crash when using custom sort functions that might cause the stack
-to change.
+C<NEXT> has been upgraded from version 0.64 to 0.65.
 
 =item *
 
-C<Errno> has been upgraded from version 1.12 to 1.13.
-
-On some platforms with unusual header files, like Win32/gcc using mingw64
-headers, some constants which weren't actually error numbers have been exposed
-by C<Errno>. This has been fixed (RT#77416).
+C<PathTools> has been upgraded from version 3.31_01 to 3.33.
 
 =item *
 
-C<ExtUtils::MakeMaker> has been upgraded from version 6.56 to 6.57_05.
+C<Unicode::Collate> has been upgraded from version 0.59 to 0.60
 
 =item *
 
-C<Filter::Simple> has been upgraded from version 0.84 to 0.85.
-
-=item *
-
-C<Math::BigInt> has been upgraded from version 1.89_01 to 1.95.
-C<Math::BigInt::Calc> has been upgraded from version 0.52 to 0.54.
-
-This fixes, among other things, incorrect results when computing binomial
-coefficients (RT#77640).
-
-=item *
-
-C<Math::BigInt::FastCalc> has been upgraded from version 0.19 to 0.22.
-
-=item *
-
-C<Math::BigRat> has been upgraded from version 0.24 to 0.25.
-
-=item *
-
-C<Module::CoreList> has been upgraded from version 2.37 to 2.38.
-
-=item *
-
-C<POSIX> has been upgraded from version 1.19 to 1.20.
-
-It now includes constants for POSIX signal constants.
-
-=item *
-
-C<Safe> has been upgraded from version 2.27 to 2.28.
-
-This fixes a possible infinite loop when looking for coderefs.
-
-=item *
-
-C<Tie::Hash> has been upgraded from version 1.03 to 1.04.
-
-Calling C<< Tie::Hash->TIEHASH() >> used to loop forever. Now it C<croak>s.
-
-=item *
-
-C<Unicode::Collate> has been upgraded from version 0.56 to 0.59.
-
-=item *
-
-C<XSLoader> has been upgraded from version 0.10 to 0.11.
+C<Unicode::Normalize> has been upgraded from version 1.06 to 1.07
 
 =back
 
@@ -304,21 +215,16 @@ XXX Changes which significantly change existing files in F<pod/> go here.
 However, any changes to F<pod/perldiag.pod> should go in the L</Diagnostics>
 section.
 
-=head3 L<perlapi>
+=head3 L<XXX>
 
 =over 4
 
 =item *
 
-Many of the optree construction functions are now documented.
+XXX Description of the change here
 
 =back
 
-=head3 L<perlfaq>
-
-L<perlfaq>, L<perlfaq2>, L<perlfaq4>, L<perlfaq5>, L<perlfaq6>, L<perlfaq8>, and
-L<perlfaq9> have seen various updates and modernisations.
-
 =head1 Diagnostics
 
 The following additions or changes have been made to diagnostic output,
@@ -338,7 +244,7 @@ XXX Newly added diagnostic messages go here
 
 =item *
 
-Use of qw(...) as parentheses is deprecated
+XXX
 
 =back
 
@@ -363,13 +269,13 @@ here. Most of these are built within the directories F<utils> and F<x2p>.
 entries for each change
 Use L<XXX> with program names to get proper documentation linking. ]
 
-=head3 L<h2ph>
+=head3 L<XXX>
 
 =over 4
 
 =item *
 
-The use of a deprecated C<goto> construct has been removed (RT#74404).
+XXX
 
 =back
 
@@ -404,13 +310,7 @@ that they represent may be covered elsewhere.
 
 =item *
 
-A rare race condition in F<t/op/while_readdir.t> has been fixed, stopping it
-from failing randomly when running tests in parallel.
-
-=item *
-
-The new F<t/op/leaky-magic.t> script tests that magic applied to variables in
-the main packages does not affect other packages.
+XXX
 
 =back
 
@@ -457,24 +357,9 @@ L</Modules and Pragmata> section.
 
 =over 4
 
-=item VMS
-
-=over 4
-
-=item *
-
-Make PerlIOUnix_open honor default permissions on VMS.
-
-When perlio became the default and unixio became the default bottom layer, the
-most common path for creating files from Perl became C<PerlIOUnix_open>, which
-has always explicitly used C<0666> as the permission mask.
-
-To avoid this, C<0777> is now passed as the permissions to C<open()>. In the VMS
-CRTL, C<0777> has a special meaning over and above intersecting with the current
-umask; specifically, it allows Unix syscalls to preserve native default
-permissions.
+=item XXX-some-platform
 
-=back
+XXX
 
 =back
 
@@ -490,27 +375,8 @@ be noted as well.
 
 =item *
 
-C<CALL_FPTR> and C<CPERLscope> have been removed deprecated.
-
-Those are left from an old implementation of C<MULTIPLICITY> using C++ objects,
-which has been removed in 5.8. Nowadays these macros do exactly nothing, so they
-shouldn't be used anymore.
-
-For compatibility, they are still defined for external C<XS> code. Only
-extensions defining C<PERL_CORE> must be updated now.
-
-=item *
-
-C<lex_stuff_pvs()> has been added as a convenience macro wrapping
-C<lex_stuff_pvn()> for literal strings.
-
-=item *
-
-The recursive part of the peephole optimizer is how hookable.
-
-In addition to C<PL_peepp>, for hooking into the toplevel peephole optimizer, a
-C<PL_rpeepp> is now available to hook into the optimizer recursing into
-side-chains of the optree.
+See L</Regular expressions retain their localeness when interpolated>,
+above.
 
 =back
 
@@ -526,88 +392,38 @@ L</Modules and Pragmata>.
 
 =item *
 
-A regression introduced in perl 5.12.0, making
-C<< my $x = 3; $x = length(undef) >> result in C<$x> set to C<3> has been
-fixed. C<$x> will now be C<undef>.
-
-=item *
-
-A fatal error in regular expressions when processing UTF-8 data has been fixed
-(RT#75680).
-
-=item *
-
-An erroneous regular expression engine optimization, that caused regex verbs
-like C<*COMMIT> to sometimes be ignored, has been removed.
-
-=item *
-
-The perl debugger now also works in taint mode (RT#76872).
-
-=item *
-
-Several memory leaks in cloning and freeing threaded perl interpreters have been
-fixed (RT#77352).
-
-=item *
-
-A possible string corruption when doing regular expression matches on overloaded
-objects has been fixed (RT#77084).
+A regular expression match in the right-hand side of a global substitution
+(C<s///g>) that is in the same scope will no longer cause match variables
+to have the wrong values on subsequent iterations. This can happen when an
+array or hash subscript is interpolated in the right-hand side, as in
+C<s|(.)|@a{ print($1), /./ }|g>
+L<[perl #19078]|http://rt.perl.org/rt3//Public/Bug/Display.html?id=19078>.
 
 =item *
 
-Magic applied to variables in the main package no longer affects other
-packages. See L</Magic Variables Outside the Main Package>, above [perl #76138].
+Constant-folding used to cause
 
-=item *
-
-Opening a glob reference via C<< open $fh, ">", \*glob >> will no longer cause
-the glob to be corrupted when the file handle is printed to. This would cause
-perl to crash whenever the glob's contents were accessed [perl #77492].
-
-=item *
-
-The postincrement and postdecrement operators, C<++> and C<--> used to cause
-leaks when being used on references. This has now been fixed.
-
-=item *
+  $text =~ ( 1 ? /phoo/ : /bear/)
 
-A bug when replacing the glob of a loop variable within the loop has been
-fixed [perl #21469]. This means the following code will no longer crash:
+to turn into
 
-    for $x (...) {
-        *x = *y;
-    }
+  $text =~ /phoo/
 
-=item *
-
-Perl would segfault if the undocumented C<Internals> functions that
-used reference prototypes were called with the C<&foo()> syntax,
-e.g. C<&Internals::SvREADONLY(undef)> [perl #77776].
-
-These functions now call C<SvROK> on their arguments before
-dereferencing them with C<SvRV>, and we test for this case in
-F<t/lib/universal.t>.
+at compile time. Now it correctly matches against C<$_>
+L<[perl #20444]|http://rt.perl.org/rt3//Public/Bug/Display.html?id=20444>.
 
 =item *
 
-When assigning a list with duplicated keys to a hash, the assignment used to
-return garbage and/or freed values:
-
-   @a = %h = (list with some duplicate keys);
-
-This has now been fixed [perl #31865].
+Parsing Perl code (either with string C<eval> or by loading modules) from
+within a C<UNITCHECK> block no longer causes the interpreter to crash
+L<[perl #70614]|http://rt.perl.org/rt3//Public/Bug/Display.html?id=70614>.
 
 =item *
 
-An earlier release of the 5.13 series of perl changed the semantics of opening a
-reference to a copy of a glob:
-
-    my $var = *STDOUT;
-    open my $fh, '>', \$var;
-
-This was a mistake, and the previous behaviour from perl 5.10 and 5.12, which is
-to treat \$var as a scalar reference, has now been restored.
+When C<-d> is used on the shebang (C<#!>) line, the debugger now has access
+to the lines of the main program. In the past, this sometimes worked and
+sometimes did not, depending on what order things happened to be arranged
+in memory.
 
 =back