source: trunk/essentials/dev-lang/perl/pod/perl56delta.pod@ 3609

Last change on this file since 3609 was 3181, checked in by bird, 19 years ago

perl 5.8.8

File size: 104.7 KB
Line 
1=head1 NAME
2
3perl56delta - what's new for perl v5.6.0
4
5=head1 DESCRIPTION
6
7This document describes differences between the 5.005 release and the 5.6.0
8release.
9
10=head1 Core Enhancements
11
12=head2 Interpreter cloning, threads, and concurrency
13
14Perl 5.6.0 introduces the beginnings of support for running multiple
15interpreters concurrently in different threads. In conjunction with
16the perl_clone() API call, which can be used to selectively duplicate
17the state of any given interpreter, it is possible to compile a
18piece of code once in an interpreter, clone that interpreter
19one or more times, and run all the resulting interpreters in distinct
20threads.
21
22On the Windows platform, this feature is used to emulate fork() at the
23interpreter level. See L<perlfork> for details about that.
24
25This feature is still in evolution. It is eventually meant to be used
26to selectively clone a subroutine and data reachable from that
27subroutine in a separate interpreter and run the cloned subroutine
28in a separate thread. Since there is no shared data between the
29interpreters, little or no locking will be needed (unless parts of
30the symbol table are explicitly shared). This is obviously intended
31to be an easy-to-use replacement for the existing threads support.
32
33Support for cloning interpreters and interpreter concurrency can be
34enabled using the -Dusethreads Configure option (see win32/Makefile for
35how to enable it on Windows.) The resulting perl executable will be
36functionally identical to one that was built with -Dmultiplicity, but
37the perl_clone() API call will only be available in the former.
38
39-Dusethreads enables the cpp macro USE_ITHREADS by default, which in turn
40enables Perl source code changes that provide a clear separation between
41the op tree and the data it operates with. The former is immutable, and
42can therefore be shared between an interpreter and all of its clones,
43while the latter is considered local to each interpreter, and is therefore
44copied for each clone.
45
46Note that building Perl with the -Dusemultiplicity Configure option
47is adequate if you wish to run multiple B<independent> interpreters
48concurrently in different threads. -Dusethreads only provides the
49additional functionality of the perl_clone() API call and other
50support for running B<cloned> interpreters concurrently.
51
52 NOTE: This is an experimental feature. Implementation details are
53 subject to change.
54
55=head2 Lexically scoped warning categories
56
57You can now control the granularity of warnings emitted by perl at a finer
58level using the C<use warnings> pragma. L<warnings> and L<perllexwarn>
59have copious documentation on this feature.
60
61=head2 Unicode and UTF-8 support
62
63Perl now uses UTF-8 as its internal representation for character
64strings. The C<utf8> and C<bytes> pragmas are used to control this support
65in the current lexical scope. See L<perlunicode>, L<utf8> and L<bytes> for
66more information.
67
68This feature is expected to evolve quickly to support some form of I/O
69disciplines that can be used to specify the kind of input and output data
70(bytes or characters). Until that happens, additional modules from CPAN
71will be needed to complete the toolkit for dealing with Unicode.
72
73 NOTE: This should be considered an experimental feature. Implementation
74 details are subject to change.
75
76=head2 Support for interpolating named characters
77
78The new C<\N> escape interpolates named characters within strings.
79For example, C<"Hi! \N{WHITE SMILING FACE}"> evaluates to a string
80with a unicode smiley face at the end.
81
82=head2 "our" declarations
83
84An "our" declaration introduces a value that can be best understood
85as a lexically scoped symbolic alias to a global variable in the
86package that was current where the variable was declared. This is
87mostly useful as an alternative to the C<vars> pragma, but also provides
88the opportunity to introduce typing and other attributes for such
89variables. See L<perlfunc/our>.
90
91=head2 Support for strings represented as a vector of ordinals
92
93Literals of the form C<v1.2.3.4> are now parsed as a string composed
94of characters with the specified ordinals. This is an alternative, more
95readable way to construct (possibly unicode) strings instead of
96interpolating characters, as in C<"\x{1}\x{2}\x{3}\x{4}">. The leading
97C<v> may be omitted if there are more than two ordinals, so C<1.2.3> is
98parsed the same as C<v1.2.3>.
99
100Strings written in this form are also useful to represent version "numbers".
101It is easy to compare such version "numbers" (which are really just plain
102strings) using any of the usual string comparison operators C<eq>, C<ne>,
103C<lt>, C<gt>, etc., or perform bitwise string operations on them using C<|>,
104C<&>, etc.
105
106In conjunction with the new C<$^V> magic variable (which contains
107the perl version as a string), such literals can be used as a readable way
108to check if you're running a particular version of Perl:
109
110 # this will parse in older versions of Perl also
111 if ($^V and $^V gt v5.6.0) {
112 # new features supported
113 }
114
115C<require> and C<use> also have some special magic to support such
116literals, but this particular usage should be avoided because it leads to
117misleading error messages under versions of Perl which don't support vector
118strings. Using a true version number will ensure correct behavior in all
119versions of Perl:
120
121 require 5.006; # run time check for v5.6
122 use 5.006_001; # compile time check for v5.6.1
123
124Also, C<sprintf> and C<printf> support the Perl-specific format flag C<%v>
125to print ordinals of characters in arbitrary strings:
126
127 printf "v%vd", $^V; # prints current version, such as "v5.5.650"
128 printf "%*vX", ":", $addr; # formats IPv6 address
129 printf "%*vb", " ", $bits; # displays bitstring
130
131See L<perldata/"Scalar value constructors"> for additional information.
132
133=head2 Improved Perl version numbering system
134
135Beginning with Perl version 5.6.0, the version number convention has been
136changed to a "dotted integer" scheme that is more commonly found in open
137source projects.
138
139Maintenance versions of v5.6.0 will be released as v5.6.1, v5.6.2 etc.
140The next development series following v5.6.0 will be numbered v5.7.x,
141beginning with v5.7.0, and the next major production release following
142v5.6.0 will be v5.8.0.
143
144The English module now sets $PERL_VERSION to $^V (a string value) rather
145than C<$]> (a numeric value). (This is a potential incompatibility.
146Send us a report via perlbug if you are affected by this.)
147
148The v1.2.3 syntax is also now legal in Perl.
149See L<Support for strings represented as a vector of ordinals> for more on that.
150
151To cope with the new versioning system's use of at least three significant
152digits for each version component, the method used for incrementing the
153subversion number has also changed slightly. We assume that versions older
154than v5.6.0 have been incrementing the subversion component in multiples of
15510. Versions after v5.6.0 will increment them by 1. Thus, using the new
156notation, 5.005_03 is the "same" as v5.5.30, and the first maintenance
157version following v5.6.0 will be v5.6.1 (which should be read as being
158equivalent to a floating point value of 5.006_001 in the older format,
159stored in C<$]>).
160
161=head2 New syntax for declaring subroutine attributes
162
163Formerly, if you wanted to mark a subroutine as being a method call or
164as requiring an automatic lock() when it is entered, you had to declare
165that with a C<use attrs> pragma in the body of the subroutine.
166That can now be accomplished with declaration syntax, like this:
167
168 sub mymethod : locked method;
169 ...
170 sub mymethod : locked method {
171 ...
172 }
173
174 sub othermethod :locked :method;
175 ...
176 sub othermethod :locked :method {
177 ...
178 }
179
180
181(Note how only the first C<:> is mandatory, and whitespace surrounding
182the C<:> is optional.)
183
184F<AutoSplit.pm> and F<SelfLoader.pm> have been updated to keep the attributes
185with the stubs they provide. See L<attributes>.
186
187=head2 File and directory handles can be autovivified
188
189Similar to how constructs such as C<< $x->[0] >> autovivify a reference,
190handle constructors (open(), opendir(), pipe(), socketpair(), sysopen(),
191socket(), and accept()) now autovivify a file or directory handle
192if the handle passed to them is an uninitialized scalar variable. This
193allows the constructs such as C<open(my $fh, ...)> and C<open(local $fh,...)>
194to be used to create filehandles that will conveniently be closed
195automatically when the scope ends, provided there are no other references
196to them. This largely eliminates the need for typeglobs when opening
197filehandles that must be passed around, as in the following example:
198
199 sub myopen {
200 open my $fh, "@_"
201 or die "Can't open '@_': $!";
202 return $fh;
203 }
204
205 {
206 my $f = myopen("</etc/motd");
207 print <$f>;
208 # $f implicitly closed here
209 }
210
211=head2 open() with more than two arguments
212
213If open() is passed three arguments instead of two, the second argument
214is used as the mode and the third argument is taken to be the file name.
215This is primarily useful for protecting against unintended magic behavior
216of the traditional two-argument form. See L<perlfunc/open>.
217
218=head2 64-bit support
219
220Any platform that has 64-bit integers either
221
222 (1) natively as longs or ints
223 (2) via special compiler flags
224 (3) using long long or int64_t
225
226is able to use "quads" (64-bit integers) as follows:
227
228=over 4
229
230=item *
231
232constants (decimal, hexadecimal, octal, binary) in the code
233
234=item *
235
236arguments to oct() and hex()
237
238=item *
239
240arguments to print(), printf() and sprintf() (flag prefixes ll, L, q)
241
242=item *
243
244printed as such
245
246=item *
247
248pack() and unpack() "q" and "Q" formats
249
250=item *
251
252in basic arithmetics: + - * / % (NOTE: operating close to the limits
253of the integer values may produce surprising results)
254
255=item *
256
257in bit arithmetics: & | ^ ~ << >> (NOTE: these used to be forced
258to be 32 bits wide but now operate on the full native width.)
259
260=item *
261
262vec()
263
264=back
265
266Note that unless you have the case (a) you will have to configure
267and compile Perl using the -Duse64bitint Configure flag.
268
269 NOTE: The Configure flags -Duselonglong and -Duse64bits have been
270 deprecated. Use -Duse64bitint instead.
271
272There are actually two modes of 64-bitness: the first one is achieved
273using Configure -Duse64bitint and the second one using Configure
274-Duse64bitall. The difference is that the first one is minimal and
275the second one maximal. The first works in more places than the second.
276
277The C<use64bitint> does only as much as is required to get 64-bit
278integers into Perl (this may mean, for example, using "long longs")
279while your memory may still be limited to 2 gigabytes (because your
280pointers could still be 32-bit). Note that the name C<64bitint> does
281not imply that your C compiler will be using 64-bit C<int>s (it might,
282but it doesn't have to): the C<use64bitint> means that you will be
283able to have 64 bits wide scalar values.
284
285The C<use64bitall> goes all the way by attempting to switch also
286integers (if it can), longs (and pointers) to being 64-bit. This may
287create an even more binary incompatible Perl than -Duse64bitint: the
288resulting executable may not run at all in a 32-bit box, or you may
289have to reboot/reconfigure/rebuild your operating system to be 64-bit
290aware.
291
292Natively 64-bit systems like Alpha and Cray need neither -Duse64bitint
293nor -Duse64bitall.
294
295Last but not least: note that due to Perl's habit of always using
296floating point numbers, the quads are still not true integers.
297When quads overflow their limits (0...18_446_744_073_709_551_615 unsigned,
298-9_223_372_036_854_775_808...9_223_372_036_854_775_807 signed), they
299are silently promoted to floating point numbers, after which they will
300start losing precision (in their lower digits).
301
302 NOTE: 64-bit support is still experimental on most platforms.
303 Existing support only covers the LP64 data model. In particular, the
304 LLP64 data model is not yet supported. 64-bit libraries and system
305 APIs on many platforms have not stabilized--your mileage may vary.
306
307=head2 Large file support
308
309If you have filesystems that support "large files" (files larger than
3102 gigabytes), you may now also be able to create and access them from
311Perl.
312
313 NOTE: The default action is to enable large file support, if
314 available on the platform.
315
316If the large file support is on, and you have a Fcntl constant
317O_LARGEFILE, the O_LARGEFILE is automatically added to the flags
318of sysopen().
319
320Beware that unless your filesystem also supports "sparse files" seeking
321to umpteen petabytes may be inadvisable.
322
323Note that in addition to requiring a proper file system to do large
324files you may also need to adjust your per-process (or your
325per-system, or per-process-group, or per-user-group) maximum filesize
326limits before running Perl scripts that try to handle large files,
327especially if you intend to write such files.
328
329Finally, in addition to your process/process group maximum filesize
330limits, you may have quota limits on your filesystems that stop you
331(your user id or your user group id) from using large files.
332
333Adjusting your process/user/group/file system/operating system limits
334is outside the scope of Perl core language. For process limits, you
335may try increasing the limits using your shell's limits/limit/ulimit
336command before running Perl. The BSD::Resource extension (not
337included with the standard Perl distribution) may also be of use, it
338offers the getrlimit/setrlimit interface that can be used to adjust
339process resource usage limits, including the maximum filesize limit.
340
341=head2 Long doubles
342
343In some systems you may be able to use long doubles to enhance the
344range and precision of your double precision floating point numbers
345(that is, Perl's numbers). Use Configure -Duselongdouble to enable
346this support (if it is available).
347
348=head2 "more bits"
349
350You can "Configure -Dusemorebits" to turn on both the 64-bit support
351and the long double support.
352
353=head2 Enhanced support for sort() subroutines
354
355Perl subroutines with a prototype of C<($$)>, and XSUBs in general, can
356now be used as sort subroutines. In either case, the two elements to
357be compared are passed as normal parameters in @_. See L<perlfunc/sort>.
358
359For unprototyped sort subroutines, the historical behavior of passing
360the elements to be compared as the global variables $a and $b remains
361unchanged.
362
363=head2 C<sort $coderef @foo> allowed
364
365sort() did not accept a subroutine reference as the comparison
366function in earlier versions. This is now permitted.
367
368=head2 File globbing implemented internally
369
370Perl now uses the File::Glob implementation of the glob() operator
371automatically. This avoids using an external csh process and the
372problems associated with it.
373
374 NOTE: This is currently an experimental feature. Interfaces and
375 implementation are subject to change.
376
377=head2 Support for CHECK blocks
378
379In addition to C<BEGIN>, C<INIT>, C<END>, C<DESTROY> and C<AUTOLOAD>,
380subroutines named C<CHECK> are now special. These are queued up during
381compilation and behave similar to END blocks, except they are called at
382the end of compilation rather than at the end of execution. They cannot
383be called directly.
384
385=head2 POSIX character class syntax [: :] supported
386
387For example to match alphabetic characters use /[[:alpha:]]/.
388See L<perlre> for details.
389
390=head2 Better pseudo-random number generator
391
392In 5.005_0x and earlier, perl's rand() function used the C library
393rand(3) function. As of 5.005_52, Configure tests for drand48(),
394random(), and rand() (in that order) and picks the first one it finds.
395
396These changes should result in better random numbers from rand().
397
398=head2 Improved C<qw//> operator
399
400The C<qw//> operator is now evaluated at compile time into a true list
401instead of being replaced with a run time call to C<split()>. This
402removes the confusing misbehaviour of C<qw//> in scalar context, which
403had inherited that behaviour from split().
404
405Thus:
406
407 $foo = ($bar) = qw(a b c); print "$foo|$bar\n";
408
409now correctly prints "3|a", instead of "2|a".
410
411=head2 Better worst-case behavior of hashes
412
413Small changes in the hashing algorithm have been implemented in
414order to improve the distribution of lower order bits in the
415hashed value. This is expected to yield better performance on
416keys that are repeated sequences.
417
418=head2 pack() format 'Z' supported
419
420The new format type 'Z' is useful for packing and unpacking null-terminated
421strings. See L<perlfunc/"pack">.
422
423=head2 pack() format modifier '!' supported
424
425The new format type modifier '!' is useful for packing and unpacking
426native shorts, ints, and longs. See L<perlfunc/"pack">.
427
428=head2 pack() and unpack() support counted strings
429
430The template character '/' can be used to specify a counted string
431type to be packed or unpacked. See L<perlfunc/"pack">.
432
433=head2 Comments in pack() templates
434
435The '#' character in a template introduces a comment up to
436end of the line. This facilitates documentation of pack()
437templates.
438
439=head2 Weak references
440
441In previous versions of Perl, you couldn't cache objects so as
442to allow them to be deleted if the last reference from outside
443the cache is deleted. The reference in the cache would hold a
444reference count on the object and the objects would never be
445destroyed.
446
447Another familiar problem is with circular references. When an
448object references itself, its reference count would never go
449down to zero, and it would not get destroyed until the program
450is about to exit.
451
452Weak references solve this by allowing you to "weaken" any
453reference, that is, make it not count towards the reference count.
454When the last non-weak reference to an object is deleted, the object
455is destroyed and all the weak references to the object are
456automatically undef-ed.
457
458To use this feature, you need the Devel::WeakRef package from CPAN, which
459contains additional documentation.
460
461 NOTE: This is an experimental feature. Details are subject to change.
462
463=head2 Binary numbers supported
464
465Binary numbers are now supported as literals, in s?printf formats, and
466C<oct()>:
467
468 $answer = 0b101010;
469 printf "The answer is: %b\n", oct("0b101010");
470
471=head2 Lvalue subroutines
472
473Subroutines can now return modifiable lvalues.
474See L<perlsub/"Lvalue subroutines">.
475
476 NOTE: This is an experimental feature. Details are subject to change.
477
478=head2 Some arrows may be omitted in calls through references
479
480Perl now allows the arrow to be omitted in many constructs
481involving subroutine calls through references. For example,
482C<< $foo[10]->('foo') >> may now be written C<$foo[10]('foo')>.
483This is rather similar to how the arrow may be omitted from
484C<< $foo[10]->{'foo'} >>. Note however, that the arrow is still
485required for C<< foo(10)->('bar') >>.
486
487=head2 Boolean assignment operators are legal lvalues
488
489Constructs such as C<($a ||= 2) += 1> are now allowed.
490
491=head2 exists() is supported on subroutine names
492
493The exists() builtin now works on subroutine names. A subroutine
494is considered to exist if it has been declared (even if implicitly).
495See L<perlfunc/exists> for examples.
496
497=head2 exists() and delete() are supported on array elements
498
499The exists() and delete() builtins now work on simple arrays as well.
500The behavior is similar to that on hash elements.
501
502exists() can be used to check whether an array element has been
503initialized. This avoids autovivifying array elements that don't exist.
504If the array is tied, the EXISTS() method in the corresponding tied
505package will be invoked.
506
507delete() may be used to remove an element from the array and return
508it. The array element at that position returns to its uninitialized
509state, so that testing for the same element with exists() will return
510false. If the element happens to be the one at the end, the size of
511the array also shrinks up to the highest element that tests true for
512exists(), or 0 if none such is found. If the array is tied, the DELETE()
513method in the corresponding tied package will be invoked.
514
515See L<perlfunc/exists> and L<perlfunc/delete> for examples.
516
517=head2 Pseudo-hashes work better
518
519Dereferencing some types of reference values in a pseudo-hash,
520such as C<< $ph->{foo}[1] >>, was accidentally disallowed. This has
521been corrected.
522
523When applied to a pseudo-hash element, exists() now reports whether
524the specified value exists, not merely if the key is valid.
525
526delete() now works on pseudo-hashes. When given a pseudo-hash element
527or slice it deletes the values corresponding to the keys (but not the keys
528themselves). See L<perlref/"Pseudo-hashes: Using an array as a hash">.
529
530Pseudo-hash slices with constant keys are now optimized to array lookups
531at compile-time.
532
533List assignments to pseudo-hash slices are now supported.
534
535The C<fields> pragma now provides ways to create pseudo-hashes, via
536fields::new() and fields::phash(). See L<fields>.
537
538 NOTE: The pseudo-hash data type continues to be experimental.
539 Limiting oneself to the interface elements provided by the
540 fields pragma will provide protection from any future changes.
541
542=head2 Automatic flushing of output buffers
543
544fork(), exec(), system(), qx//, and pipe open()s now flush buffers
545of all files opened for output when the operation was attempted. This
546mostly eliminates confusing buffering mishaps suffered by users unaware
547of how Perl internally handles I/O.
548
549This is not supported on some platforms like Solaris where a suitably
550correct implementation of fflush(NULL) isn't available.
551
552=head2 Better diagnostics on meaningless filehandle operations
553
554Constructs such as C<< open(<FH>) >> and C<< close(<FH>) >>
555are compile time errors. Attempting to read from filehandles that
556were opened only for writing will now produce warnings (just as
557writing to read-only filehandles does).
558
559=head2 Where possible, buffered data discarded from duped input filehandle
560
561C<< open(NEW, "<&OLD") >> now attempts to discard any data that
562was previously read and buffered in C<OLD> before duping the handle.
563On platforms where doing this is allowed, the next read operation
564on C<NEW> will return the same data as the corresponding operation
565on C<OLD>. Formerly, it would have returned the data from the start
566of the following disk block instead.
567
568=head2 eof() has the same old magic as <>
569
570C<eof()> would return true if no attempt to read from C<< <> >> had
571yet been made. C<eof()> has been changed to have a little magic of its
572own, it now opens the C<< <> >> files.
573
574=head2 binmode() can be used to set :crlf and :raw modes
575
576binmode() now accepts a second argument that specifies a discipline
577for the handle in question. The two pseudo-disciplines ":raw" and
578":crlf" are currently supported on DOS-derivative platforms.
579See L<perlfunc/"binmode"> and L<open>.
580
581=head2 C<-T> filetest recognizes UTF-8 encoded files as "text"
582
583The algorithm used for the C<-T> filetest has been enhanced to
584correctly identify UTF-8 content as "text".
585
586=head2 system(), backticks and pipe open now reflect exec() failure
587
588On Unix and similar platforms, system(), qx() and open(FOO, "cmd |")
589etc., are implemented via fork() and exec(). When the underlying
590exec() fails, earlier versions did not report the error properly,
591since the exec() happened to be in a different process.
592
593The child process now communicates with the parent about the
594error in launching the external command, which allows these
595constructs to return with their usual error value and set $!.
596
597=head2 Improved diagnostics
598
599Line numbers are no longer suppressed (under most likely circumstances)
600during the global destruction phase.
601
602Diagnostics emitted from code running in threads other than the main
603thread are now accompanied by the thread ID.
604
605Embedded null characters in diagnostics now actually show up. They
606used to truncate the message in prior versions.
607
608$foo::a and $foo::b are now exempt from "possible typo" warnings only
609if sort() is encountered in package C<foo>.
610
611Unrecognized alphabetic escapes encountered when parsing quote
612constructs now generate a warning, since they may take on new
613semantics in later versions of Perl.
614
615Many diagnostics now report the internal operation in which the warning
616was provoked, like so:
617
618 Use of uninitialized value in concatenation (.) at (eval 1) line 1.
619 Use of uninitialized value in print at (eval 1) line 1.
620
621Diagnostics that occur within eval may also report the file and line
622number where the eval is located, in addition to the eval sequence
623number and the line number within the evaluated text itself. For
624example:
625
626 Not enough arguments for scalar at (eval 4)[newlib/perl5db.pl:1411] line 2, at EOF
627
628=head2 Diagnostics follow STDERR
629
630Diagnostic output now goes to whichever file the C<STDERR> handle
631is pointing at, instead of always going to the underlying C runtime
632library's C<stderr>.
633
634=head2 More consistent close-on-exec behavior
635
636On systems that support a close-on-exec flag on filehandles, the
637flag is now set for any handles created by pipe(), socketpair(),
638socket(), and accept(), if that is warranted by the value of $^F
639that may be in effect. Earlier versions neglected to set the flag
640for handles created with these operators. See L<perlfunc/pipe>,
641L<perlfunc/socketpair>, L<perlfunc/socket>, L<perlfunc/accept>,
642and L<perlvar/$^F>.
643
644=head2 syswrite() ease-of-use
645
646The length argument of C<syswrite()> has become optional.
647
648=head2 Better syntax checks on parenthesized unary operators
649
650Expressions such as:
651
652 print defined(&foo,&bar,&baz);
653 print uc("foo","bar","baz");
654 undef($foo,&bar);
655
656used to be accidentally allowed in earlier versions, and produced
657unpredictable behaviour. Some produced ancillary warnings
658when used in this way; others silently did the wrong thing.
659
660The parenthesized forms of most unary operators that expect a single
661argument now ensure that they are not called with more than one
662argument, making the cases shown above syntax errors. The usual
663behaviour of:
664
665 print defined &foo, &bar, &baz;
666 print uc "foo", "bar", "baz";
667 undef $foo, &bar;
668
669remains unchanged. See L<perlop>.
670
671=head2 Bit operators support full native integer width
672
673The bit operators (& | ^ ~ << >>) now operate on the full native
674integral width (the exact size of which is available in $Config{ivsize}).
675For example, if your platform is either natively 64-bit or if Perl
676has been configured to use 64-bit integers, these operations apply
677to 8 bytes (as opposed to 4 bytes on 32-bit platforms).
678For portability, be sure to mask off the excess bits in the result of
679unary C<~>, e.g., C<~$x & 0xffffffff>.
680
681=head2 Improved security features
682
683More potentially unsafe operations taint their results for improved
684security.
685
686The C<passwd> and C<shell> fields returned by the getpwent(), getpwnam(),
687and getpwuid() are now tainted, because the user can affect their own
688encrypted password and login shell.
689
690The variable modified by shmread(), and messages returned by msgrcv()
691(and its object-oriented interface IPC::SysV::Msg::rcv) are also tainted,
692because other untrusted processes can modify messages and shared memory
693segments for their own nefarious purposes.
694
695=head2 More functional bareword prototype (*)
696
697Bareword prototypes have been rationalized to enable them to be used
698to override builtins that accept barewords and interpret them in
699a special way, such as C<require> or C<do>.
700
701Arguments prototyped as C<*> will now be visible within the subroutine
702as either a simple scalar or as a reference to a typeglob.
703See L<perlsub/Prototypes>.
704
705=head2 C<require> and C<do> may be overridden
706
707C<require> and C<do 'file'> operations may be overridden locally
708by importing subroutines of the same name into the current package
709(or globally by importing them into the CORE::GLOBAL:: namespace).
710Overriding C<require> will also affect C<use>, provided the override
711is visible at compile-time.
712See L<perlsub/"Overriding Built-in Functions">.
713
714=head2 $^X variables may now have names longer than one character
715
716Formerly, $^X was synonymous with ${"\cX"}, but $^XY was a syntax
717error. Now variable names that begin with a control character may be
718arbitrarily long. However, for compatibility reasons, these variables
719I<must> be written with explicit braces, as C<${^XY}> for example.
720C<${^XYZ}> is synonymous with ${"\cXYZ"}. Variable names with more
721than one control character, such as C<${^XY^Z}>, are illegal.
722
723The old syntax has not changed. As before, `^X' may be either a
724literal control-X character or the two-character sequence `caret' plus
725`X'. When braces are omitted, the variable name stops after the
726control character. Thus C<"$^XYZ"> continues to be synonymous with
727C<$^X . "YZ"> as before.
728
729As before, lexical variables may not have names beginning with control
730characters. As before, variables whose names begin with a control
731character are always forced to be in package `main'. All such variables
732are reserved for future extensions, except those that begin with
733C<^_>, which may be used by user programs and are guaranteed not to
734acquire special meaning in any future version of Perl.
735
736=head2 New variable $^C reflects C<-c> switch
737
738C<$^C> has a boolean value that reflects whether perl is being run
739in compile-only mode (i.e. via the C<-c> switch). Since
740BEGIN blocks are executed under such conditions, this variable
741enables perl code to determine whether actions that make sense
742only during normal running are warranted. See L<perlvar>.
743
744=head2 New variable $^V contains Perl version as a string
745
746C<$^V> contains the Perl version number as a string composed of
747characters whose ordinals match the version numbers, i.e. v5.6.0.
748This may be used in string comparisons.
749
750See C<Support for strings represented as a vector of ordinals> for an
751example.
752
753=head2 Optional Y2K warnings
754
755If Perl is built with the cpp macro C<PERL_Y2KWARN> defined,
756it emits optional warnings when concatenating the number 19
757with another number.
758
759This behavior must be specifically enabled when running Configure.
760See F<INSTALL> and F<README.Y2K>.
761
762=head2 Arrays now always interpolate into double-quoted strings
763
764In double-quoted strings, arrays now interpolate, no matter what. The
765behavior in earlier versions of perl 5 was that arrays would interpolate
766into strings if the array had been mentioned before the string was
767compiled, and otherwise Perl would raise a fatal compile-time error.
768In versions 5.000 through 5.003, the error was
769
770 Literal @example now requires backslash
771
772In versions 5.004_01 through 5.6.0, the error was
773
774 In string, @example now must be written as \@example
775
776The idea here was to get people into the habit of writing
777C<"fred\@example.com"> when they wanted a literal C<@> sign, just as
778they have always written C<"Give me back my \$5"> when they wanted a
779literal C<$> sign.
780
781Starting with 5.6.1, when Perl now sees an C<@> sign in a
782double-quoted string, it I<always> attempts to interpolate an array,
783regardless of whether or not the array has been used or declared
784already. The fatal error has been downgraded to an optional warning:
785
786 Possible unintended interpolation of @example in string
787
788This warns you that C<"[email protected]"> is going to turn into
789C<fred.com> if you don't backslash the C<@>.
790See http://www.plover.com/~mjd/perl/at-error.html for more details
791about the history here.
792
793=head2 @- and @+ provide starting/ending offsets of regex matches
794
795The new magic variables @- and @+ provide the starting and ending
796offsets, respectively, of $&, $1, $2, etc. See L<perlvar> for
797details.
798
799=head1 Modules and Pragmata
800
801=head2 Modules
802
803=over 4
804
805=item attributes
806
807While used internally by Perl as a pragma, this module also
808provides a way to fetch subroutine and variable attributes.
809See L<attributes>.
810
811=item B
812
813The Perl Compiler suite has been extensively reworked for this
814release. More of the standard Perl testsuite passes when run
815under the Compiler, but there is still a significant way to
816go to achieve production quality compiled executables.
817
818 NOTE: The Compiler suite remains highly experimental. The
819 generated code may not be correct, even when it manages to execute
820 without errors.
821
822=item Benchmark
823
824Overall, Benchmark results exhibit lower average error and better timing
825accuracy.
826
827You can now run tests for I<n> seconds instead of guessing the right
828number of tests to run: e.g., timethese(-5, ...) will run each
829code for at least 5 CPU seconds. Zero as the "number of repetitions"
830means "for at least 3 CPU seconds". The output format has also
831changed. For example:
832
833 use Benchmark;$x=3;timethese(-5,{a=>sub{$x*$x},b=>sub{$x**2}})
834
835will now output something like this:
836
837 Benchmark: running a, b, each for at least 5 CPU seconds...
838 a: 5 wallclock secs ( 5.77 usr + 0.00 sys = 5.77 CPU) @ 200551.91/s (n=1156516)
839 b: 4 wallclock secs ( 5.00 usr + 0.02 sys = 5.02 CPU) @ 159605.18/s (n=800686)
840
841New features: "each for at least N CPU seconds...", "wallclock secs",
842and the "@ operations/CPU second (n=operations)".
843
844timethese() now returns a reference to a hash of Benchmark objects containing
845the test results, keyed on the names of the tests.
846
847timethis() now returns the iterations field in the Benchmark result object
848instead of 0.
849
850timethese(), timethis(), and the new cmpthese() (see below) can also take
851a format specifier of 'none' to suppress output.
852
853A new function countit() is just like timeit() except that it takes a
854TIME instead of a COUNT.
855
856A new function cmpthese() prints a chart comparing the results of each test
857returned from a timethese() call. For each possible pair of tests, the
858percentage speed difference (iters/sec or seconds/iter) is shown.
859
860For other details, see L<Benchmark>.
861
862=item ByteLoader
863
864The ByteLoader is a dedicated extension to generate and run
865Perl bytecode. See L<ByteLoader>.
866
867=item constant
868
869References can now be used.
870
871The new version also allows a leading underscore in constant names, but
872disallows a double leading underscore (as in "__LINE__"). Some other names
873are disallowed or warned against, including BEGIN, END, etc. Some names
874which were forced into main:: used to fail silently in some cases; now they're
875fatal (outside of main::) and an optional warning (inside of main::).
876The ability to detect whether a constant had been set with a given name has
877been added.
878
879See L<constant>.
880
881=item charnames
882
883This pragma implements the C<\N> string escape. See L<charnames>.
884
885=item Data::Dumper
886
887A C<Maxdepth> setting can be specified to avoid venturing
888too deeply into deep data structures. See L<Data::Dumper>.
889
890The XSUB implementation of Dump() is now automatically called if the
891C<Useqq> setting is not in use.
892
893Dumping C<qr//> objects works correctly.
894
895=item DB
896
897C<DB> is an experimental module that exposes a clean abstraction
898to Perl's debugging API.
899
900=item DB_File
901
902DB_File can now be built with Berkeley DB versions 1, 2 or 3.
903See C<ext/DB_File/Changes>.
904
905=item Devel::DProf
906
907Devel::DProf, a Perl source code profiler has been added. See
908L<Devel::DProf> and L<dprofpp>.
909
910=item Devel::Peek
911
912The Devel::Peek module provides access to the internal representation
913of Perl variables and data. It is a data debugging tool for the XS programmer.
914
915=item Dumpvalue
916
917The Dumpvalue module provides screen dumps of Perl data.
918
919=item DynaLoader
920
921DynaLoader now supports a dl_unload_file() function on platforms that
922support unloading shared objects using dlclose().
923
924Perl can also optionally arrange to unload all extension shared objects
925loaded by Perl. To enable this, build Perl with the Configure option
926C<-Accflags=-DDL_UNLOAD_ALL_AT_EXIT>. (This maybe useful if you are
927using Apache with mod_perl.)
928
929=item English
930
931$PERL_VERSION now stands for C<$^V> (a string value) rather than for C<$]>
932(a numeric value).
933
934=item Env
935
936Env now supports accessing environment variables like PATH as array
937variables.
938
939=item Fcntl
940
941More Fcntl constants added: F_SETLK64, F_SETLKW64, O_LARGEFILE for
942large file (more than 4GB) access (NOTE: the O_LARGEFILE is
943automatically added to sysopen() flags if large file support has been
944configured, as is the default), Free/Net/OpenBSD locking behaviour
945flags F_FLOCK, F_POSIX, Linux F_SHLCK, and O_ACCMODE: the combined
946mask of O_RDONLY, O_WRONLY, and O_RDWR. The seek()/sysseek()
947constants SEEK_SET, SEEK_CUR, and SEEK_END are available via the
948C<:seek> tag. The chmod()/stat() S_IF* constants and S_IS* functions
949are available via the C<:mode> tag.
950
951=item File::Compare
952
953A compare_text() function has been added, which allows custom
954comparison functions. See L<File::Compare>.
955
956=item File::Find
957
958File::Find now works correctly when the wanted() function is either
959autoloaded or is a symbolic reference.
960
961A bug that caused File::Find to lose track of the working directory
962when pruning top-level directories has been fixed.
963
964File::Find now also supports several other options to control its
965behavior. It can follow symbolic links if the C<follow> option is
966specified. Enabling the C<no_chdir> option will make File::Find skip
967changing the current directory when walking directories. The C<untaint>
968flag can be useful when running with taint checks enabled.
969
970See L<File::Find>.
971
972=item File::Glob
973
974This extension implements BSD-style file globbing. By default,
975it will also be used for the internal implementation of the glob()
976operator. See L<File::Glob>.
977
978=item File::Spec
979
980New methods have been added to the File::Spec module: devnull() returns
981the name of the null device (/dev/null on Unix) and tmpdir() the name of
982the temp directory (normally /tmp on Unix). There are now also methods
983to convert between absolute and relative filenames: abs2rel() and
984rel2abs(). For compatibility with operating systems that specify volume
985names in file paths, the splitpath(), splitdir(), and catdir() methods
986have been added.
987
988=item File::Spec::Functions
989
990The new File::Spec::Functions modules provides a function interface
991to the File::Spec module. Allows shorthand
992
993 $fullname = catfile($dir1, $dir2, $file);
994
995instead of
996
997 $fullname = File::Spec->catfile($dir1, $dir2, $file);
998
999=item Getopt::Long
1000
1001Getopt::Long licensing has changed to allow the Perl Artistic License
1002as well as the GPL. It used to be GPL only, which got in the way of
1003non-GPL applications that wanted to use Getopt::Long.
1004
1005Getopt::Long encourages the use of Pod::Usage to produce help
1006messages. For example:
1007
1008 use Getopt::Long;
1009 use Pod::Usage;
1010 my $man = 0;
1011 my $help = 0;
1012 GetOptions('help|?' => \$help, man => \$man) or pod2usage(2);
1013 pod2usage(1) if $help;
1014 pod2usage(-exitstatus => 0, -verbose => 2) if $man;
1015
1016 __END__
1017
1018 =head1 NAME
1019
1020 sample - Using Getopt::Long and Pod::Usage
1021
1022 =head1 SYNOPSIS
1023
1024 sample [options] [file ...]
1025
1026 Options:
1027 -help brief help message
1028 -man full documentation
1029
1030 =head1 OPTIONS
1031
1032 =over 8
1033
1034 =item B<-help>
1035
1036 Print a brief help message and exits.
1037
1038 =item B<-man>
1039
1040 Prints the manual page and exits.
1041
1042 =back
1043
1044 =head1 DESCRIPTION
1045
1046 B<This program> will read the given input file(s) and do something
1047 useful with the contents thereof.
1048
1049 =cut
1050
1051See L<Pod::Usage> for details.
1052
1053A bug that prevented the non-option call-back <> from being
1054specified as the first argument has been fixed.
1055
1056To specify the characters < and > as option starters, use ><. Note,
1057however, that changing option starters is strongly deprecated.
1058
1059=item IO
1060
1061write() and syswrite() will now accept a single-argument
1062form of the call, for consistency with Perl's syswrite().
1063
1064You can now create a TCP-based IO::Socket::INET without forcing
1065a connect attempt. This allows you to configure its options
1066(like making it non-blocking) and then call connect() manually.
1067
1068A bug that prevented the IO::Socket::protocol() accessor
1069from ever returning the correct value has been corrected.
1070
1071IO::Socket::connect now uses non-blocking IO instead of alarm()
1072to do connect timeouts.
1073
1074IO::Socket::accept now uses select() instead of alarm() for doing
1075timeouts.
1076
1077IO::Socket::INET->new now sets $! correctly on failure. $@ is
1078still set for backwards compatibility.
1079
1080=item JPL
1081
1082Java Perl Lingo is now distributed with Perl. See jpl/README
1083for more information.
1084
1085=item lib
1086
1087C<use lib> now weeds out any trailing duplicate entries.
1088C<no lib> removes all named entries.
1089
1090=item Math::BigInt