Fix description of "." in unpack() in perl5100delta
[p5sagit/p5-mst-13.2.git] / pod / perl5100delta.pod
1 TODO: perl591delta and further
2
3 =head1 NAME
4
5 perldelta - what is new for perl 5.10.0
6
7 =head1 DESCRIPTION
8
9 This document describes the differences between the 5.8.8 release and
10 the 5.10.0 release.
11
12 Many of the bug fixes in 5.10.0 were already seen in the 5.8.X maintenance
13 releases; they are not duplicated here and are documented in the set of
14 man pages named perl58[1-8]?delta.
15
16 =head1 Incompatible Changes
17
18 =head2 Packing and UTF-8 strings
19
20 =for XXX update this
21
22 The semantics of pack() and unpack() regarding UTF-8-encoded data has been
23 changed. Processing is now by default character per character instead of
24 byte per byte on the underlying encoding. Notably, code that used things
25 like C<pack("a*", $string)> to see through the encoding of string will now
26 simply get back the original $string. Packed strings can also get upgraded
27 during processing when you store upgraded characters. You can get the old
28 behaviour by using C<use bytes>.
29
30 To be consistent with pack(), the C<C0> in unpack() templates indicates
31 that the data is to be processed in character mode, i.e. character by
32 character; on the contrary, C<U0> in unpack() indicates UTF-8 mode, where
33 the packed string is processed in its UTF-8-encoded Unicode form on a byte
34 by byte basis. This is reversed with regard to perl 5.8.X.
35
36 Moreover, C<C0> and C<U0> can also be used in pack() templates to specify
37 respectively character and byte modes.
38
39 C<C0> and C<U0> in the middle of a pack or unpack format now switch to the
40 specified encoding mode, honoring parens grouping. Previously, parens were
41 ignored.
42
43 Also, there is a new pack() character format, C<W>, which is intended to
44 replace the old C<C>. C<C> is kept for unsigned chars coded as bytes in
45 the strings internal representation. C<W> represents unsigned (logical)
46 character values, which can be greater than 255. It is therefore more
47 robust when dealing with potentially UTF-8-encoded data (as C<C> will wrap
48 values outside the range 0..255, and not respect the string encoding).
49
50 In practice, that means that pack formats are now encoding-neutral, except
51 C<C>.
52
53 For consistency, C<A> in unpack() format now trims all Unicode whitespace
54 from the end of the string. Before perl 5.9.2, it used to strip only the
55 classical ASCII space characters.
56
57 =head2 Byte/character count feature in unpack()
58
59 A new unpack() template character, C<".">, returns the number of bytes or
60 characters (depending on the selected encoding mode, see above) read so far.
61
62 =head2 The C<$*> and C<$#> variables have been removed
63
64 C<$*>, which was deprecated in favor of the C</s> and C</m> regexp
65 modifiers, has been removed.
66
67 The deprecated C<$#> variable (output format for numbers) has been
68 removed.
69
70 Two new warnings, C<$#/$* is no longer supported>, have been added.
71
72 =head2 substr() lvalues are no longer fixed-length
73
74 The lvalues returned by the three argument form of substr() used to be a
75 "fixed length window" on the original string. In some cases this could
76 cause surprising action at distance or other undefined behaviour. Now the
77 length of the window adjusts itself to the length of the string assigned to
78 it.
79
80 =head2 Parsing of C<-f _>
81
82 The identifier C<_> is now forced to be a bareword after a filetest
83 operator. This solves a number of misparsing issues when a global C<_>
84 subroutine is defined.
85
86 =head2 C<:unique>
87
88 The C<:unique> attribute has been made a no-op, since its current
89 implementation was fundamentally flawed and not threadsafe.
90
91 =head2 Scoping of the C<sort> pragma
92
93 The C<sort> pragma is now lexically scoped. Its effect used to be global.
94
95 =head2 Scoping of C<bignum>, C<bigint>, C<bigrat>
96
97 The three numeric pragmas C<bignum>, C<bigint> and C<bigrat> are now
98 lexically scoped. (Tels)
99
100 =head2 Effect of pragmas in eval
101
102 The compile-time value of the C<%^H> hint variable can now propagate into
103 eval("")uated code. This makes it more useful to implement lexical
104 pragmas.
105
106 As a side-effect of this, the overloaded-ness of constants now propagates
107 into eval("").
108
109 =head2 chdir FOO
110
111 A bareword argument to chdir() is now recognized as a file handle.
112 Earlier releases interpreted the bareword as a directory name.
113 (Gisle Aas)
114
115 =head2 Handling of .pmc files
116
117 An old feature of perl was that before C<require> or C<use> look for a
118 file with a F<.pm> extension, they will first look for a similar filename
119 with a F<.pmc> extension. If this file is found, it will be loaded in
120 place of any potentially existing file ending in a F<.pm> extension.
121
122 Previously, F<.pmc> files were loaded only if more recent than the
123 matching F<.pm> file. Starting with 5.9.4, they'll be always loaded if
124 they exist.
125
126 =head2 @- and @+ in patterns
127
128 The special arrays C<@-> and C<@+> are no longer interpolated in regular
129 expressions. (Sadahiro Tomoyuki)
130
131 =head2 $AUTOLOAD can now be tainted
132
133 If you call a subroutine by a tainted name, and if it defers to an
134 AUTOLOAD function, then $AUTOLOAD will be (correctly) tainted.
135 (Rick Delaney)
136
137 =head2 Tainting and printf
138
139 When perl is run under taint mode, C<printf()> and C<sprintf()> will now
140 reject any tainted format argument. (Rafael Garcia-Suarez)
141
142 =head2 undef and signal handlers
143
144 Undefining or deleting a signal handler via C<undef $SIG{FOO}> is now
145 equivalent to setting it to C<'DEFAULT'>. (Rafael Garcia-Suarez)
146
147 =head2 strictures and array/hash dereferencing in defined()
148
149 C<defined @$foo> and C<defined %$bar> are now subject to C<strict 'refs'>
150 (that is, C<$foo> and C<$bar> shall be proper references there.)
151 (Nicholas Clark)
152
153 (However, C<defined(@foo)> and C<defined(%bar)> are discouraged constructs
154 anyway.)
155
156 =head2 C<(?p{})> has been removed
157
158 The regular expression construct C<(?p{})>, which was deprecated in perl
159 5.8, has been removed. Use C<(??{})> instead. (Rafael Garcia-Suarez)
160
161 =head2 Pseudo-hashes have been removed
162
163 Support for pseudo-hashes has been removed from Perl 5.9. (The C<fields>
164 pragma remains here, but uses an alternate implementation.)
165
166 =head2 Removal of the bytecode compiler and of perlcc
167
168 C<perlcc>, the byteloader and the supporting modules (B::C, B::CC,
169 B::Bytecode, etc.) are no longer distributed with the perl sources. Those
170 experimental tools have never worked reliably, and, due to the lack of
171 volunteers to keep them in line with the perl interpreter developments, it
172 was decided to remove them instead of shipping a broken version of those.
173 The last version of those modules can be found with perl 5.9.4.
174
175 However the B compiler framework stays supported in the perl core, as with
176 the more useful modules it has permitted (among others, B::Deparse and
177 B::Concise).
178
179 =head2 Removal of the JPL
180
181 The JPL (Java-Perl Linguo) has been removed from the perl sources tarball.
182
183 =head2 Recursive inheritance detected earlier
184
185 Perl will now immediately throw an exception if you modify any package's
186 C<@ISA> in such a way that it would cause recursive inheritance.
187
188 Previously, the exception would not occur until Perl attempted to make
189 use of the recursive inheritance while resolving a method or doing a
190 C<$foo-E<gt>isa($bar)> lookup.
191
192 =head1 Core Enhancements
193
194 =head2 The C<feature> pragma
195
196 The C<feature> pragma is used to enable new syntax that would break Perl's
197 backwards-compatibility with older releases of the language. It's a lexical
198 pragma, like C<strict> or C<warnings>.
199
200 Currently the following new features are available: C<switch> (adds a
201 switch statement), C<say> (adds a C<say> built-in function), and C<state>
202 (adds an C<state> keyword for declaring "static" variables). Those
203 features are described in their own sections of this document.
204
205 The C<feature> pragma is also implicitly loaded when you require a minimal
206 perl version (with the C<use VERSION> construct) greater than, or equal
207 to, 5.9.5. See L<feature> for details.
208
209 =head2 New B<-E> command-line switch
210
211 B<-E> is equivalent to B<-e>, but it implicitly enables all
212 optional features (like C<use feature ":5.10">).
213
214 =head2 Defined-or operator
215
216 A new operator C<//> (defined-or) has been implemented.
217 The following statement:
218
219     $a // $b
220
221 is merely equivalent to
222
223    defined $a ? $a : $b
224
225 and
226
227    $c //= $d;
228
229 can now be used instead of
230
231    $c = $d unless defined $c;
232
233 The C<//> operator has the same precedence and associativity as C<||>.
234 Special care has been taken to ensure that this operator Do What You Mean
235 while not breaking old code, but some edge cases involving the empty
236 regular expression may now parse differently.  See L<perlop> for
237 details.
238
239 =head2 Switch and Smart Match operator
240
241 Perl 5 now has a switch statement. It's available when C<use feature
242 'switch'> is in effect. This feature introduces three new keywords,
243 C<given>, C<when>, and C<default>:
244
245     given ($foo) {
246         when (/^abc/) { $abc = 1; }
247         when (/^def/) { $def = 1; }
248         when (/^xyz/) { $xyz = 1; }
249         default { $nothing = 1; }
250     }
251
252 A more complete description of how Perl matches the switch variable
253 against the C<when> conditions is given in L<perlsyn/"Switch statements">.
254
255 This kind of match is called I<smart match>, and it's also possible to use
256 it outside of switch statements, via the new C<~~> operator. See
257 L<perlsyn/"Smart matching in detail">.
258
259 This feature was contributed by Robin Houston.
260
261 =head2 Regular expressions
262
263 =over 4
264
265 =item Recursive Patterns
266
267 It is now possible to write recursive patterns without using the C<(??{})>
268 construct. This new way is more efficient, and in many cases easier to
269 read.
270
271 Each capturing parenthesis can now be treated as an independent pattern
272 that can be entered by using the C<(?PARNO)> syntax (C<PARNO> standing for
273 "parenthesis number"). For example, the following pattern will match
274 nested balanced angle brackets:
275
276     /
277      ^                      # start of line
278      (                      # start capture buffer 1
279         <                   #   match an opening angle bracket
280         (?:                 #   match one of:
281             (?>             #     don't backtrack over the inside of this group
282                 [^<>]+      #       one or more non angle brackets
283             )               #     end non backtracking group
284         |                   #     ... or ...
285             (?1)            #     recurse to bracket 1 and try it again
286         )*                  #   0 or more times.
287         >                   #   match a closing angle bracket
288      )                      # end capture buffer one
289      $                      # end of line
290     /x
291
292 Note, users experienced with PCRE will find that the Perl implementation
293 of this feature differs from the PCRE one in that it is possible to
294 backtrack into a recursed pattern, whereas in PCRE the recursion is
295 atomic or "possessive" in nature. (Yves Orton)
296
297 =item Named Capture Buffers
298
299 It is now possible to name capturing parenthesis in a pattern and refer to
300 the captured contents by name. The naming syntax is C<< (?<NAME>....) >>.
301 It's possible to backreference to a named buffer with the C<< \k<NAME> >>
302 syntax. In code, the new magical hashes C<%+> and C<%-> can be used to
303 access the contents of the capture buffers.
304
305 Thus, to replace all doubled chars, one could write
306
307     s/(?<letter>.)\k<letter>/$+{letter}/g
308
309 Only buffers with defined contents will be "visible" in the C<%+> hash, so
310 it's possible to do something like
311
312     foreach my $name (keys %+) {
313         print "content of buffer '$name' is $+{$name}\n";
314     }
315
316 The C<%-> hash is a bit more complete, since it will contain array refs
317 holding values from all capture buffers similarly named, if there should
318 be many of them.
319
320 C<%+> and C<%-> are implemented as tied hashes through the new module
321 C<Tie::Hash::NamedCapture>.
322
323 Users exposed to the .NET regex engine will find that the perl
324 implementation differs in that the numerical ordering of the buffers
325 is sequential, and not "unnamed first, then named". Thus in the pattern
326
327    /(A)(?<B>B)(C)(?<D>D)/
328
329 $1 will be 'A', $2 will be 'B', $3 will be 'C' and $4 will be 'D' and not
330 $1 is 'A', $2 is 'C' and $3 is 'B' and $4 is 'D' that a .NET programmer
331 would expect. This is considered a feature. :-) (Yves Orton)
332
333 =item Possessive Quantifiers
334
335 Perl now supports the "possessive quantifier" syntax of the "atomic match"
336 pattern. Basically a possessive quantifier matches as much as it can and never
337 gives any back. Thus it can be used to control backtracking. The syntax is
338 similar to non-greedy matching, except instead of using a '?' as the modifier
339 the '+' is used. Thus C<?+>, C<*+>, C<++>, C<{min,max}+> are now legal
340 quantifiers. (Yves Orton)
341
342 =item Backtracking control verbs
343
344 The regex engine now supports a number of special-purpose backtrack
345 control verbs: (*THEN), (*PRUNE), (*MARK), (*SKIP), (*COMMIT), (*FAIL)
346 and (*ACCEPT). See L<perlre> for their descriptions. (Yves Orton)
347
348 =item Relative backreferences
349
350 A new syntax C<\g{N}> or C<\gN> where "N" is a decimal integer allows a
351 safer form of back-reference notation as well as allowing relative
352 backreferences. This should make it easier to generate and embed patterns
353 that contain backreferences. See L<perlre/"Capture buffers">. (Yves Orton)
354
355 =item C<\K> escape
356
357 The functionality of Jeff Pinyan's module Regexp::Keep has been added to
358 the core. You can now use in regular expressions the special escape C<\K>
359 as a way to do something like floating length positive lookbehind. It is
360 also useful in substitutions like:
361
362   s/(foo)bar/$1/g
363
364 that can now be converted to
365
366   s/foo\Kbar//g
367
368 which is much more efficient. (Yves Orton)
369
370 =item Vertical and horizontal whitespace, and linebreak
371
372 Regular expressions now recognize the C<\v> and C<\h> escapes, that match
373 vertical and horizontal whitespace, respectively. C<\V> and C<\H>
374 logically match their complements.
375
376 C<\R> matches a generic linebreak, that is, vertical whitespace, plus
377 the multi-character sequence C<"\x0D\x0A">.
378
379 =back
380
381 =head2 C<say()>
382
383 say() is a new built-in, only available when C<use feature 'say'> is in
384 effect, that is similar to print(), but that implicitly appends a newline
385 to the printed string. See L<perlfunc/say>. (Robin Houston)
386
387 =head2 Lexical C<$_>
388
389 The default variable C<$_> can now be lexicalized, by declaring it like
390 any other lexical variable, with a simple
391
392     my $_;
393
394 The operations that default on C<$_> will use the lexically-scoped
395 version of C<$_> when it exists, instead of the global C<$_>.
396
397 In a C<map> or a C<grep> block, if C<$_> was previously my'ed, then the
398 C<$_> inside the block is lexical as well (and scoped to the block).
399
400 In a scope where C<$_> has been lexicalized, you can still have access to
401 the global version of C<$_> by using C<$::_>, or, more simply, by
402 overriding the lexical declaration with C<our $_>.
403
404 =head2 The C<_> prototype
405
406 A new prototype character has been added. C<_> is equivalent to C<$> (it
407 denotes a scalar), but defaults to C<$_> if the corresponding argument
408 isn't supplied. Due to the optional nature of the argument, you can only
409 use it at the end of a prototype, or before a semicolon.
410
411 This has a small incompatible consequence: the prototype() function has
412 been adjusted to return C<_> for some built-ins in appropriate cases (for
413 example, C<prototype('CORE::rmdir')>). (Rafael Garcia-Suarez)
414
415 =head2 UNITCHECK blocks
416
417 C<UNITCHECK>, a new special code block has been introduced, in addition to
418 C<BEGIN>, C<CHECK>, C<INIT> and C<END>.
419
420 C<CHECK> and C<INIT> blocks, while useful for some specialized purposes,
421 are always executed at the transition between the compilation and the
422 execution of the main program, and thus are useless whenever code is
423 loaded at runtime. On the other hand, C<UNITCHECK> blocks are executed
424 just after the unit which defined them has been compiled. See L<perlmod>
425 for more information. (Alex Gough)
426
427 =head2 New Pragma, C<mro>
428
429 A new pragma, C<mro> (for Method Resolution Order) has been added. It
430 permits to switch, on a per-class basis, the algorithm that perl uses to
431 find inherited methods in case of a mutiple inheritance hierachy. The
432 default MRO hasn't changed (DFS, for Depth First Search). Another MRO is
433 available: the C3 algorithm. See L<mro> for more information.
434 (Brandon Black)
435
436 Note that, due to changes in the implentation of class hierarchy search,
437 code that used to undef the C<*ISA> glob will most probably break. Anyway,
438 undef'ing C<*ISA> had the side-effect of removing the magic on the @ISA
439 array and should not have been done in the first place.
440
441 =head2 readpipe() is now overridable
442
443 The built-in function readpipe() is now overridable. Overriding it permits
444 also to override its operator counterpart, C<qx//> (a.k.a. C<``>).
445 Moreover, it now defaults to C<$_> if no argument is provided. (Rafael
446 Garcia-Suarez)
447
448 =head2 default argument for readline()
449
450 readline() now defaults to C<*ARGV> if no argument is provided. (Rafael
451 Garcia-Suarez)
452
453 =head2 state() variables
454
455 A new class of variables has been introduced. State variables are similar
456 to C<my> variables, but are declared with the C<state> keyword in place of
457 C<my>. They're visible only in their lexical scope, but their value is
458 persistent: unlike C<my> variables, they're not undefined at scope entry,
459 but retain their previous value. (Rafael Garcia-Suarez, Nicholas Clark)
460
461 To use state variables, one needs to enable them by using
462
463     use feature "state";
464
465 or by using the C<-E> command-line switch in one-liners.
466 See L<perlsub/"Persistent variables via state()">.
467
468 =head2 Stacked filetest operators
469
470 As a new form of syntactic sugar, it's now possible to stack up filetest
471 operators. You can now write C<-f -w -x $file> in a row to mean
472 C<-x $file && -w _ && -f _>. See L<perlfunc/-X>.
473
474 =head2 UNIVERSAL::DOES()
475
476 The C<UNIVERSAL> class has a new method, C<DOES()>. It has been added to
477 solve semantic problems with the C<isa()> method. C<isa()> checks for
478 inheritance, while C<DOES()> has been designed to be overridden when
479 module authors use other types of relations between classes (in addition
480 to inheritance). (chromatic)
481
482 See L<< UNIVERSAL/"$obj->DOES( ROLE )" >>.
483
484 =head2 C<CLONE_SKIP()>
485
486 Perl has now support for the C<CLONE_SKIP> special subroutine. Like
487 C<CLONE>, C<CLONE_SKIP> is called once per package; however, it is called
488 just before cloning starts, and in the context of the parent thread. If it
489 returns a true value, then no objects of that class will be cloned. See
490 L<perlmod> for details. (Contributed by Dave Mitchell.)
491
492 =head2 Formats
493
494 Formats were improved in several ways. A new field, C<^*>, can be used for
495 variable-width, one-line-at-a-time text. Null characters are now handled
496 correctly in picture lines. Using C<@#> and C<~~> together will now
497 produce a compile-time error, as those format fields are incompatible.
498 L<perlform> has been improved, and miscellaneous bugs fixed.
499
500 =head2 Byte-order modifiers for pack() and unpack()
501
502 There are two new byte-order modifiers, C<E<gt>> (big-endian) and C<E<lt>>
503 (little-endian), that can be appended to most pack() and unpack() template
504 characters and groups to force a certain byte-order for that type or group.
505 See L<perlfunc/pack> and L<perlpacktut> for details.
506
507 =head2 C<no VERSION>
508
509 You can now use C<no> followed by a version number to specify that you
510 want to use a version of perl older than the specified one.
511
512 =head2 C<chdir>, C<chmod> and C<chown> on filehandles
513
514 C<chdir>, C<chmod> and C<chown> can now work on filehandles as well as
515 filenames, if the system supports respectively C<fchdir>, C<fchmod> and
516 C<fchown>, thanks to a patch provided by Gisle Aas.
517
518 =head2 OS groups
519
520 C<$(> and C<$)> now return groups in the order where the OS returns them,
521 thanks to Gisle Aas. This wasn't previously the case.
522
523 =head2 Recursive sort subs
524
525 You can now use recursive subroutines with sort(), thanks to Robin Houston.
526
527 =head2 Exceptions in constant folding
528
529 The constant folding routine is now wrapped in an exception handler, and
530 if folding throws an exception (such as attempting to evaluate 0/0), perl
531 now retains the current optree, rather than aborting the whole program.
532 (Nicholas Clark, Dave Mitchell)
533
534 =head2 Source filters in @INC
535
536 It's possible to enhance the mechanism of subroutine hooks in @INC by
537 adding a source filter on top of the filehandle opened and returned by the
538 hook. This feature was planned a long time ago, but wasn't quite working
539 until now. See L<perlfunc/require> for details. (Nicholas Clark)
540
541 =head2 New internal variables
542
543 =over 4
544
545 =item C<${^RE_DEBUG_FLAGS}>
546
547 This variable controls what debug flags are in effect for the regular
548 expression engine when running under C<use re "debug">. See L<re> for
549 details.
550
551 =item C<${^CHILD_ERROR_NATIVE}>
552
553 This variable gives the native status returned by the last pipe close,
554 backtick command, successful call to wait() or waitpid(), or from the
555 system() operator. See L<perlrun> for details. (Contributed by Gisle Aas.)
556
557 =back
558
559 =head2 Miscellaneous
560
561 C<unpack()> now defaults to unpacking the C<$_> variable.
562
563 C<mkdir()> without arguments now defaults to C<$_>.
564
565 The internal dump output has been improved, so that non-printable characters
566 such as newline and backspace are output in C<\x> notation, rather than
567 octal.
568
569 The B<-C> option can no longer be used on the C<#!> line. It wasn't
570 working there anyway.
571
572 =head2 UCD 5.0.0
573
574 The copy of the Unicode Character Database included in Perl 5 has
575 been updated to version 5.0.0.
576
577
578 =head2 MAD
579
580 MAD, which stands for I<Misc Attribute Decoration>, is a
581 still-in-development work leading to a Perl 5 to Perl 6 converter. To
582 enable it, it's necessary to pass the argument C<-Dmad> to Configure. The
583 obtained perl isn't binary compatible with a regular perl 5.9.4, and has
584 space and speed penalties; moreover not all regression tests still pass
585 with it. (Larry Wall, Nicholas Clark)
586
587 =head1 Modules and Pragmata
588 =head1 Utility Changes
589 =head1 New Documentation
590 =head1 Performance Enhancements
591 =head1 Installation and Configuration Improvements
592 =head1 Selected Bug Fixes
593 =head1 New or Changed Diagnostics
594 =head1 Changed Internals
595 =head1 New Tests
596 =head1 Known Problems
597 =head1 Platform Specific Problems
598 =head1 Reporting Bugs
599
600 =head1 SEE ALSO
601
602 The F<Changes> file and the perl590delta to perl595delta man pages for
603 exhaustive details on what changed.
604
605 The F<INSTALL> file for how to build Perl.
606
607 The F<README> file for general stuff.
608
609 The F<Artistic> and F<Copying> files for copyright information.
610
611 =cut