Commit | Line | Data |
f6eae373 |
1 | =head1 NAME |
2 | |
3 | perldelta - what is new for perl v5.9.5 |
4 | |
5 | =head1 DESCRIPTION |
6 | |
7 | This document describes differences between the 5.9.4 and the 5.9.5 |
8 | development releases. See L<perl590delta>, L<perl591delta>, |
9 | L<perl592delta>, L<perl593delta> and L<perl594delta> for the differences |
10 | between 5.8.0 and 5.9.4. |
11 | |
12 | =head1 Incompatible Changes |
13 | |
14 | =head1 Core Enhancements |
15 | |
072f65b4 |
16 | =head2 Regular expressions |
17 | |
18 | =over 4 |
19 | |
20 | =item Recursive Patterns |
21 | |
22 | It is now possible to write recursive patterns without using the C<(??{})> |
23 | construct. This new way is more efficient, and in many cases easier to |
24 | read. |
25 | |
26 | Each capturing parenthesis can now be treated as an independent pattern |
27 | that can be entered by using the C<(?PARNO)> syntax (C<PARNO> standing for |
28 | "parenthesis number"). For example, the following pattern will match |
29 | nested balanced angle brackets: |
30 | |
31 | / |
32 | ^ # start of line |
33 | ( # start capture buffer 1 |
34 | < # match an opening angle bracket |
35 | (?: # match one of: |
36 | (?> # don't backtrack over the inside of this group |
37 | [^<>]+ # one or more non angle brackets |
38 | ) # end non backtracking group |
39 | | # ... or ... |
40 | (?1) # recurse to bracket 1 and try it again |
41 | )* # 0 or more times. |
42 | > # match a closing angle bracket |
43 | ) # end capture buffer one |
44 | $ # end of line |
45 | /x |
46 | |
47 | Note, users experienced with PCRE will find that the Perl implementation |
48 | of this feature differs from the PCRE one in that it is possible to |
49 | backtrack into a recursed pattern, whereas in PCRE the recursion is |
50 | atomic or "possessive" in nature. |
51 | |
52 | =item Named Capture Buffers |
53 | |
54 | It is now possible to name capturing parenthesis in a pattern and refer to |
55 | the captured contents by name. The naming syntax is C<< (?<NAME>....) >>. |
56 | It's possible to backreference to a named buffer with the C<< \k<NAME> >> |
57 | syntax. In code, the new magical hash C<%+> can be used to access the |
58 | contents of the buffers. |
59 | |
60 | Thus, to replace all doubled chars, one could write |
61 | |
62 | s/(?<letter>.)\k<letter>/$+{letter}/g |
63 | |
64 | Only buffers with defined contents will be "visible" in the hash, so |
65 | it's possible to do something like |
66 | |
67 | foreach my $name (keys %+) { |
68 | print "content of buffer '$name' is $+{$name}\n"; |
69 | } |
70 | |
71 | Users exposed to the .NET regex engine will find that the perl |
72 | implementation differs in that the numerical ordering of the buffers |
73 | is sequential, and not "unnamed first, then named". Thus in the pattern |
74 | |
75 | /(A)(?<B>B)(C)(?<D>D)/ |
76 | |
77 | $1 will be 'A', $2 will be 'B', $3 will be 'C' and $4 will be 'D' and not |
78 | $1 is 'A', $2 is 'C' and $3 is 'B' and $4 is 'D' that a .NET programmer |
79 | would expect. This is considered a feature. :-) |
80 | |
b9b4dddf |
81 | =item Possessive Quantifiers |
82 | |
83 | Perl now supports the "possessive quantifier" syntax of the "atomic match" |
84 | pattern. Basically a possessive quantifier matches as much as it can and never |
85 | gives any back. Thus it can be used to control backtracking. The syntax is |
86 | similar to non-greedy matching, except instead of using a '?' as the modifier |
87 | the '+' is used. Thus C<?+>, C<*+>, C<++>, C<{min,max}+> are now legal |
88 | quantifiers. |
89 | |
072f65b4 |
90 | =back |
91 | |
d5494b07 |
92 | =head2 The C<_> prototype |
93 | |
94 | A new prototype character has been added. C<_> is equivalent to C<$> (it |
95 | denotes a scalar), but defaults to C<$_> if the corresponding argument |
96 | isn't supplied. Due to the optional nature of the argument, you can only |
97 | use it at the end of a prototype, or before a semicolon. |
98 | |
f6eae373 |
99 | =head1 Modules and Pragmas |
100 | |
101 | =head2 New Core Modules |
102 | |
d5494b07 |
103 | =head2 Module changes |
104 | |
105 | =over 4 |
106 | |
107 | =item C<base> |
108 | |
109 | The C<base> pragma now warns if a class tries to inherit from itself. |
110 | |
18857c0b |
111 | =item C<warnings> |
112 | |
113 | The C<warnings> pragma doesn't load C<Carp> anymore. That means that code |
114 | that used C<Carp> routines without having loaded it at compile time might |
115 | need to be adjusted; typically, the following (faulty) code won't work |
116 | anymore, and will require parentheses to be added after the function name: |
117 | |
118 | use warnings; |
119 | require Carp; |
120 | Carp::confess "argh"; |
121 | |
d5494b07 |
122 | =back |
123 | |
f6eae373 |
124 | =head1 Utility Changes |
125 | |
126 | =head1 Documentation |
127 | |
128 | =head1 Performance Enhancements |
129 | |
130 | =head1 Installation and Configuration Improvements |
131 | |
132 | =head1 Selected Bug Fixes |
133 | |
134 | =head1 New or Changed Diagnostics |
135 | |
136 | =head1 Changed Internals |
137 | |
138 | =head1 Known Problems |
139 | |
140 | =head2 Platform Specific Problems |
141 | |
142 | =head1 Reporting Bugs |
143 | |
144 | If you find what you think is a bug, you might check the articles |
145 | recently posted to the comp.lang.perl.misc newsgroup and the perl |
146 | bug database at http://rt.perl.org/rt3/ . There may also be |
147 | information at http://www.perl.org/ , the Perl Home Page. |
148 | |
149 | If you believe you have an unreported bug, please run the B<perlbug> |
150 | program included with your release. Be sure to trim your bug down |
151 | to a tiny but sufficient test case. Your bug report, along with the |
152 | output of C<perl -V>, will be sent off to perlbug@perl.org to be |
153 | analysed by the Perl porting team. |
154 | |
155 | =head1 SEE ALSO |
156 | |
157 | The F<Changes> file for exhaustive details on what changed. |
158 | |
159 | The F<INSTALL> file for how to build Perl. |
160 | |
161 | The F<README> file for general stuff. |
162 | |
163 | The F<Artistic> and F<Copying> files for copyright information. |
164 | |
165 | =cut |