This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Introduce the charnames pragma.
[perl5.git] / pod / perldelta.pod
1 =head1 NAME
2
3 perldelta - what's new for perl v5.6 (as of v5.005_58)
4
5 =head1 DESCRIPTION
6
7 This is an unsupported alpha release, meant for intrepid Perl developers
8 only.  The included sources may not even build correctly on some platforms.
9 Subscribing to perl5-porters is the best way to monitor and contribute
10 to the progress of development releases (see www.perl.org for info).
11
12 This document describes differences between the 5.005 release and this one.
13
14 =head1 Incompatible Changes
15
16 =head2 Perl Source Incompatibilities
17
18 TODO
19
20 =head2 C Source Incompatibilities
21
22 =over 4
23
24 =item C<PERL_POLLUTE>
25
26 Release 5.005 grandfathered old global symbol names by providing preprocessor
27 macros for extension source compatibility.  As of release 5.6, these
28 preprocessor definitions are not available by default.  You need to explicitly
29 compile perl with C<-DPERL_POLLUTE> to get these definitions.  For
30 extensions still using the old symbols, this option can be
31 specified via MakeMaker:
32
33     perl Makefile.PL POLLUTE=1
34
35 =item C<PERL_IMPLICIT_CONTEXT>
36
37 This new build option provides a set of macros for all API functions
38 such that an implicit interpreter/thread context argument is passed to
39 every API function.  As a result of this, something like C<sv_setsv(foo,bar)>
40 amounts to a macro invocation that actually translates to something like
41 C<Perl_sv_setsv(my_perl,foo,bar)>.  While this is generally expected
42 to not have any significant source compatibility issues, the difference
43 between a macro and a real function call will need to be considered.
44
45 This means that there B<is> a source compatibility issue as a result of
46 this if your extensions attempt to use pointers to any of the Perl API
47 functions.
48
49 Note that the above issue is not relevant to the default build of
50 Perl, whose interfaces continue to match those of prior versions
51 (but subject to the other options described here).
52
53 For testing purposes, the 5.005_58 release automatically enables
54 PERL_IMPLICIT_CONTEXT whenever Perl is built with -Dusethreads or
55 -Dusemultiplicity.
56
57 See L<perlguts/"The Perl API"> for detailed information on the
58 ramifications of building Perl using this option.
59
60 =item C<PERL_POLLUTE_MALLOC>
61
62 Enabling Perl's malloc in release 5.005 and earlier caused
63 the namespace of system versions of the malloc family of functions to
64 be usurped by the Perl versions, since by default they used the
65 same names.
66
67 Besides causing problems on platforms that do not allow these functions to
68 be cleanly replaced, this also meant that the system versions could not
69 be called in programs that used Perl's malloc.  Previous versions of Perl
70 have allowed this behaviour to be suppressed with the HIDEMYMALLOC and
71 EMBEDMYMALLOC preprocessor definitions.
72
73 As of release 5.6, Perl's malloc family of functions have default names
74 distinct from the system versions.  You need to explicitly compile perl with
75 C<-DPERL_POLLUTE_MALLOC> to get the older behaviour.  HIDEMYMALLOC
76 and EMBEDMYMALLOC have no effect, since the behaviour they enabled is now
77 the default.
78
79 Note that these functions do B<not> constitute Perl's memory allocation API.
80 See L<perlguts/"Memory Allocation"> for further information about that.
81
82 =item C<PL_na> and C<dTHR> Issues
83
84 The C<PL_na> global is now thread local, so a C<dTHR> declaration is needed
85 in the scope in which the global appears.  XSUBs should handle this automatically,
86 but if you have used C<PL_na> in support functions, you either need to
87 change the C<PL_na> to a local variable (which is recommended), or put in
88 a C<dTHR>.
89
90 =back
91
92 =head2 Compatible C Source API Changes
93
94 =over
95
96 =item C<PATCHLEVEL> is now C<PERL_VERSION>
97
98 The cpp macros C<PERL_REVISION>, C<PERL_VERSION>, and C<PERL_SUBVERSION>
99 are now available by default from perl.h, and reflect the base revision,
100 patchlevel, and subversion respectively.  C<PERL_REVISION> had no
101 prior equivalent, while C<PERL_VERSION> and C<PERL_SUBVERSION> were
102 previously available as C<PATCHLEVEL> and C<SUBVERSION>.
103
104 The new names cause less pollution of the B<cpp> namespace and reflect what
105 the numbers have come to stand for in common practice.  For compatibility,
106 the old names are still supported when F<patchlevel.h> is explicitly
107 included (as required before), so there is no source incompatibility
108 from the change.
109
110 =back
111
112 =head2 Binary Incompatibilities
113
114 The default build of this release is binary compatible with the 5.005
115 release or its maintenance versions.
116
117 The usethreads or usemultiplicity builds are B<not> binary compatible
118 with the corresponding builds in 5.005.
119
120 =head1 Core Changes
121
122 =head2 Unicode and UTF-8 support
123
124 Perl can optionally use UTF-8 as its internal representation for character
125 strings.  The C<use utf8> pragma enables this support in the current lexical
126 scope.  See L<utf8> for more information.
127
128 =head2 Lexically scoped warning categories
129
130 You can now control the granularity of warnings emitted by perl at a finer
131 level using the C<use warning> pragma.  See L<warning> and L<perllexwarn>
132 for details.
133
134 =head2 Binary numbers supported
135
136 Binary numbers are now supported as literals, in s?printf formats, and
137 C<oct()>:
138
139     $answer = 0b101010;
140     printf "The answer is: %b\n", oct("0b101010");
141
142 =head2 syswrite() ease-of-use
143
144 The length argument of C<syswrite()> is now optional.
145
146 =head2 64-bit support
147
148 All platforms that have 64-bit integers either (a) natively as longs
149 or ints (b) via special compiler flags (c) using long long are able to
150 use "quads" (64-integers) as follows:
151
152 =over 4
153
154 =item constants in the code 
155
156 =item arguments to oct() and hex()
157
158 =item arguments to print(), printf() and sprintf()
159
160 =item pack() and unpack() "q" format
161
162 =item in basic arithmetics
163
164 =back
165
166 Note that unless you have the case (a) you will have to configure
167 and compile Perl using the -Duse64bits Configure flag.
168
169 Unfortunately, bit operations (&, <<, ...) and vec() do not work,
170 they are limited to 32 bits.
171
172 Last but not least: note that due to Perl's tendency to always use
173 floating point numbers the quads are not true integers.  They may lose
174 their precision due to rounding errors, and when they get large their
175 less significant digits will fall off.
176
177 =head2 Better syntax checks on parenthesized unary operators
178
179 Expressions such as:
180
181     print defined(&foo,&bar,&baz);
182     print uc("foo","bar","baz");
183     undef($foo,&bar);
184
185 used to be accidentally allowed in earlier versions, and produced
186 unpredictable behaviour.  Some produced ancillary warnings
187 when used in this way; others silently did the wrong thing.
188
189 The parenthesized forms of most unary operators that expect a single
190 argument now ensure that they are not called with more than one
191 argument, making the cases shown above syntax errors.  The usual
192 behaviour of:
193
194     print defined &foo, &bar, &baz;
195     print uc "foo", "bar", "baz";
196     undef $foo, &bar;
197
198 remains unchanged.  See L<perlop>.
199
200 =head2 POSIX character class syntax [: :] supported
201
202 For example to match alphabetic characters use /[[:alpha:]]/.
203 See L<perlre> for details.
204
205 =head2 Improved C<qw//> operator
206
207 The C<qw//> operator is now evaluated at compile time into a true list
208 instead of being replaced with a run time call to C<split()>.  This
209 removes the confusing misbehaviour of C<qw//> in scalar context, which
210 had inherited that behaviour from split().
211
212 Thus:
213
214     $foo = ($bar) = qw(a b c); print "$foo|$bar\n";
215
216 now correctly prints "3|a", instead of "2|a".
217
218 =head2 pack() format 'Z' supported
219
220 The new format type 'Z' is useful for packing and unpacking null-terminated
221 strings.  See L<perlfunc/"pack">.
222
223 =head2 pack() format modifier '!' supported
224
225 The new format type modifier '!' is useful for packing and unpacking
226 native shorts, ints, and longs.  See L<perlfunc/"pack">.
227
228 =head2 pack() and unpack() support counted strings
229
230 The template character '#' can be used to specify a counted string
231 type to be packed or unpacked.  See L<perlfunc/"pack">.
232
233 =head2 $^X variables may now have names longer than one character
234
235 Formerly, $^X was synonymous with ${"\cX"}, but $^XY was a syntax
236 error.  Now variable names that begin with a control character may be
237 arbitrarily long.  However, for compatibility reasons, these variables
238 I<must> be written with explicit braces, as C<${^XY}> for example.
239 C<${^XYZ}> is synonymous with ${"\cXYZ"}.  Variable names with more
240 than one control character, such as C<${^XY^Z}>, are illegal.
241
242 The old syntax has not changed.  As before, `^X' may be either a
243 literal control-X character or the two-character sequence `caret' plus
244 `X'.  When braces are omitted, the variable name stops after the
245 control character.  Thus C<"$^XYZ"> continues to be synonymous with
246 C<$^X . "YZ"> as before.
247
248 As before, lexical variables may not have names beginning with control
249 characters.  As before, variables whose names begin with a control
250 character are always forced to be in package `main'.  All such variables
251 are reserved for future extensions, except those that begin with
252 C<^_>, which may be used by user programs and is guaranteed not to
253 acquire special meaning in any future version of Perl.
254
255 =head1 Significant bug fixes
256
257 =head2 E<lt>HANDLEE<gt> on empty files
258
259 With C<$/> set to C<undef>, slurping an empty file returns a string of
260 zero length (instead of C<undef>, as it used to) the first time the
261 HANDLE is read.  Further reads yield C<undef>.
262
263 This means that the following will append "foo" to an empty file (it used
264 to do nothing):
265
266     perl -0777 -pi -e 's/^/foo/' empty_file
267
268 The behaviour of:
269
270     perl -pi -e 's/^/foo/' empty_file
271
272 is unchanged (it continues to leave the file empty).
273
274 =head2 C<eval '...'> improvements
275
276 Line numbers (as reflected by caller() and most diagnostics) within
277 C<eval '...'> were often incorrect when here documents were involved.
278 This has been corrected.
279
280 Lexical lookups for variables appearing in C<eval '...'> within
281 functions that were themselves called within an C<eval '...'> were
282 searching the wrong place for lexicals.  The lexical search now
283 correctly ends at the subroutine's block boundary.
284
285 Parsing of here documents used to be flawed when they appeared as
286 the replacement expression in C<eval 's/.../.../e'>.  This has
287 been fixed.
288
289 =head2 Automatic flushing of output buffers
290
291 fork(), exec(), system(), qx//, and pipe open()s now flush buffers
292 of all files opened for output when the operation
293 was attempted.  This mostly eliminates confusing 
294 buffering mishaps suffered by users unaware of how Perl internally
295 handles I/O.
296
297 =head2 Better diagnostics on meaningless filehandle operations
298
299 Constructs such as C<open(E<lt>FHE<gt>)> and C<close(E<lt>FHE<gt>)>
300 are compile time errors.  Attempting to read from filehandles that
301 were opened only for writing will now produce warnings (just as
302 writing to read-only filehandles does).
303
304 =head1 Supported Platforms
305
306 =over 4
307
308 =item *
309
310 VM/ESA is now supported.
311
312 =item *
313
314 Siemens BS2000 is now supported under the POSIX Shell.
315
316 =item *
317
318 The Mach CThreads (NEXTSTEP, OPENSTEP) are now supported by the Thread
319 extension.
320
321 =item *
322
323 GNU/Hurd is now supported.
324
325 =item *
326
327 Rhapsody is now supported.
328
329 =item *
330
331 EPOC is is now supported (on Psion 5).
332
333 =back
334
335 =head1 New tests
336
337 =over 4
338
339 =item   op/io_const
340
341 IO constants (SEEK_*, _IO*).
342
343 =item   op/io_dir
344
345 Directory-related IO methods (new, read, close, rewind, tied delete).
346
347 =item   op/io_multihomed
348
349 INET sockets with multi-homed hosts.
350
351 =item   op/io_poll
352
353 IO poll().
354
355 =item   op/io_unix
356
357 UNIX sockets.
358
359 =item   op/filetest
360
361 File test operators.
362
363 =item   op/lex_assign
364
365 Verify operations that access pad objects (lexicals and temporaries).
366
367 =back
368
369 =head1 Modules and Pragmata
370
371 =head2 Modules
372
373 =over 4
374
375 =item ByteLoader
376
377 The ByteLoader is a dedication extension to generate and run
378 Perl bytecode.  See L<ByteLoader>.
379
380 =item B
381
382 The Perl Compiler suite has been extensively reworked for this
383 release.
384
385 =item Devel::DProf
386
387 Devel::DProf, a Perl source code profiler has been added.
388
389 =item Dumpvalue
390
391 Added Dumpvalue module provides screen dumps of Perl data.
392
393 =item Benchmark
394
395 You can now run tests for I<n> seconds instead of guessing the right
396 number of tests to run: e.g. timethese(-5, ...) will run each 
397 code for at least 5 CPU seconds.  Zero as the "number of repetitions"
398 means "for at least 3 CPU seconds".  The output format has also
399 changed.  For example:
400
401 use Benchmark;$x=3;timethese(-5,{a=>sub{$x*$x},b=>sub{$x**2}})
402
403 will now output something like this:
404
405 Benchmark: running a, b, each for at least 5 CPU seconds...
406          a:  5 wallclock secs ( 5.77 usr +  0.00 sys =  5.77 CPU) @ 200551.91/s (n=1156516)
407          b:  4 wallclock secs ( 5.00 usr +  0.02 sys =  5.02 CPU) @ 159605.18/s (n=800686)
408
409 New features: "each for at least N CPU seconds...", "wallclock secs",
410 and the "@ operations/CPU second (n=operations)".
411
412 =item Devel::Peek
413
414 The Devel::Peek module provides access to the internal representation
415 of Perl variables and data.  It is a data debugging tool for the XS programmer.
416
417 =item Fcntl
418
419 More Fcntl constants added: F_SETLK64, F_SETLKW64, O_LARGEFILE for
420 large (more than 4G) file access (64-bit support is not yet
421 working, though, so no need to get overly excited), Free/Net/OpenBSD
422 locking behaviour flags F_FLOCK, F_POSIX, Linux F_SHLCK, and
423 O_ACCMODE: the mask of O_RDONLY, O_WRONLY, and O_RDWR.
424
425 =item File::Spec
426
427 New methods have been added to the File::Spec module: devnull() returns
428 the name of the null device (/dev/null on Unix) and tmpdir() the name of
429 the temp directory (normally /tmp on Unix).  There are now also methods
430 to convert between absolute and relative filenames: abs2rel() and
431 rel2abs().  For compatibility with operating systems that specify volume
432 names in file paths, the splitpath(), splitdir(), and catdir() methods
433 have been added.
434
435 =item File::Spec::Functions
436
437 The new File::Spec::Functions modules provides a function interface
438 to the File::Spec module.  Allows shorthand
439
440     $fullname = catfile($dir1, $dir2, $file);
441
442 instead of
443
444     $fullname = File::Spec->catfile($dir1, $dir2, $file);
445
446 =item Math::BigInt
447
448 The logical operations C<E<lt>E<lt>>, C<E<gt>E<gt>>, C<&>, C<|>,
449 and C<~> are now supported on bigints.
450
451 =item Math::Complex
452
453 The accessor methods Re, Im, arg, abs, rho, and theta can now also
454 act as mutators (accessor $z->Re(), mutator $z->Re(3)).
455
456 =item Math::Trig
457
458 A little bit of radial trigonometry (cylindrical and spherical),
459 radial coordinate conversions, and the great circle distance were added.
460
461 =item SDBM_File
462
463 An EXISTS method has been added to this module (and sdbm_exists() has
464 been added to the underlying sdbm library), so one can now call exists
465 on an SDBM_File tied hash and get the correct result, rather than a
466 runtime error.
467
468 =item Time::Local
469
470 The timelocal() and timegm() functions used to silently return bogus
471 results when the date exceeded the machine's integer range.  They
472 now consistently croak() if the date falls in an unsupported range.
473
474 =item Win32
475
476 The error return value in list context has been changed for all functions
477 that return a list of values.  Previously these functions returned a list
478 with a single element C<undef> if an error occurred.  Now these functions
479 return the empty list in these situations.  This applies to the following
480 functions:
481
482     Win32::FsType
483     Win32::GetOSVersion
484
485 The remaining functions are unchanged and continue to return C<undef> on
486 error even in list context.
487
488 The Win32::SetLastError(ERROR) function has been added as a complement
489 to the Win32::GetLastError() function.
490
491 The new Win32::GetFullPathName(FILENAME) returns the full absolute
492 pathname for FILENAME in scalar context.  In list context it returns
493 a two-element list containing the fully qualified directory name and
494 the filename.
495
496 =item DBM Filters
497
498 A new feature called "DBM Filters" has been added to all the
499 DBM modules--DB_File, GDBM_File, NDBM_File, ODBM_File, and SDBM_File.
500 DBM Filters add four new methods to each DBM module:
501
502     filter_store_key
503     filter_store_value
504     filter_fetch_key
505     filter_fetch_value
506
507 These can be used to filter key-value pairs before the pairs are
508 written to the database or just after they are read from the database.
509 See L<perldbmfilter> for further information.
510
511 =back
512
513 =head2 Pragmata
514
515 C<use utf8> to enable UTF-8 and Unicode support.
516
517 C<use caller 'encoding'> allows modules to inherit pragmatic attributes
518 from the caller's context.  C<encoding> is currently the only supported
519 attribute.
520
521 Lexical warnings pragma, C<use warning;>, to control optional warnings.
522
523 C<use filetest> to control the behaviour of filetests (C<-r> C<-w> ...).
524 Currently only one subpragma implemented, "use filetest 'access';",
525 that enables the use of access(2) or equivalent to check
526 permissions instead of using stat(2) as usual.  This matters
527 in filesystems where there are ACLs (access control lists): the
528 stat(2) might lie, but access(2) knows better.
529
530 =head1 Utility Changes
531
532 Todo.
533
534 =head1 Documentation Changes
535
536 =over 4
537
538 =item perlopentut.pod
539
540 A tutorial on using open() effectively.
541
542 =item perlreftut.pod
543
544 A tutorial that introduces the essentials of references.
545
546 =item perltootc.pod
547
548 A tutorial on managing class data for object modules.
549
550 =back
551
552 =head1 New Diagnostics
553
554 =item /%s/: Unrecognized escape \\%c passed through
555
556 (W) You used a backslash-character combination which is not recognized
557 by Perl.  This combination appears in an interpolated variable or a
558 C<'>-delimited regular expression.
559
560 =item Filehandle %s opened only for output
561
562 (W) You tried to read from a filehandle opened only for writing.  If you
563 intended it to be a read-write filehandle, you needed to open it with
564 "+E<lt>" or "+E<gt>" or "+E<gt>E<gt>" instead of with "E<lt>" or nothing.  If
565 you intended only to read from the file, use "E<lt>".  See
566 L<perlfunc/open>.
567
568 =item Missing command in piped open
569
570 (W) You used the C<open(FH, "| command")> or C<open(FH, "command |")>
571 construction, but the command was missing or blank.
572
573 =item Unrecognized escape \\%c passed through
574
575 (W) You used a backslash-character combination which is not recognized
576 by Perl.
577
578 =item defined(@array) is deprecated
579
580 (D) defined() is not usually useful on arrays because it checks for an
581 undefined I<scalar> value.  If you want to see if the array is empty,
582 just use C<if (@array) { # not empty }> for example.  
583
584 =item defined(%hash) is deprecated
585
586 (D) defined() is not usually useful on hashes because it checks for an
587 undefined I<scalar> value.  If you want to see if the hash is empty,
588 just use C<if (%hash) { # not empty }> for example.  
589
590 =head1 Obsolete Diagnostics
591
592 Todo.
593
594 =head1 Configuration Changes
595
596 =head2 installusrbinperl
597
598 You can use "Configure -Uinstallusrbinperl" which causes installperl
599 to skip installing perl also as /usr/bin/perl.  This is useful if you
600 prefer not to modify /usr/bin for some reason or another but harmful
601 because many scripts assume to find Perl in /usr/bin/perl.
602
603 =head2 SOCKS support
604
605 You can use "Configure -Dusesocks" which causes Perl to probe
606 for the SOCKS proxy protocol library, http://www.socks.nec.com/
607
608 =head1 BUGS
609
610 If you find what you think is a bug, you might check the headers of
611 articles recently posted to the comp.lang.perl.misc newsgroup.
612 There may also be information at http://www.perl.com/perl/, the Perl
613 Home Page.
614
615 If you believe you have an unreported bug, please run the B<perlbug>
616 program included with your release.  Make sure to trim your bug down
617 to a tiny but sufficient test case.  Your bug report, along with the
618 output of C<perl -V>, will be sent off to perlbug@perl.com to be
619 analysed by the Perl porting team.
620
621 =head1 SEE ALSO
622
623 The F<Changes> file for exhaustive details on what changed.
624
625 The F<INSTALL> file for how to build Perl.
626
627 The F<README> file for general stuff.
628
629 The F<Artistic> and F<Copying> files for copyright information.
630
631 =head1 HISTORY
632
633 Written by Gurusamy Sarathy <F<gsar@umich.edu>>, with many contributions
634 from The Perl Porters.
635
636 Send omissions or corrections to <F<perlbug@perl.com>>.
637
638 =cut