3 perlnews - what's new for perl5.004
7 This document describes differences between the 5.003 release (as
8 documented in I<Programming Perl>, second edition--the Camel Book) and
11 =head1 Supported Environments
13 Perl5.004 builds out of the box on Unix, Plan9, LynxOS, VMS, OS/2,
18 Most importantly, many bugs were fixed. See the F<Changes>
19 file in the distribution for details.
21 =head2 Compilation Option: Binary Compatibility With 5.003
23 There is a new Configure question that asks if you want to maintain
24 binary compatibility with Perl 5.003. If you choose binary
25 compatibility, you do not have to recompile your extensions, but you
26 might have symbol conflicts if you embed Perl in another application,
27 just as in the 5.003 release.
29 =head2 New Opcode Module and Revised Safe Module
31 A new Opcode module supports the creation, manipulation and
32 application of opcode masks. The revised Safe module has a new API
33 and is implemented using the new Opcode module. Please read the new
34 Opcode and Safe documentation.
36 =head2 Internal Change: FileHandle Deprecated
38 Filehandles are now stored internally as type IO::Handle.
39 Although C<use FileHandle> and C<*STDOUT{FILEHANDLE}>
40 are still supported for backwards compatibility
41 C<use IO::Handle> (or C<IO::Seekable> or C<IO::File>) and
42 C<*STDOUT{IO}> are the way of the future.
44 =head2 Internal Change: PerlIO internal IO abstraction interface
46 It is now possible to build Perl with AT&T's sfio IO package
47 instead of stdio. See L<perlapio> for more details, and
48 the F<INSTALL> file for how to use it.
50 =head2 New and Changed Built-in Variables
56 Extended error message under some platforms ($EXTENDED_OS_ERROR
57 if you C<use English>).
61 The current set of syntax checks enabled by C<use strict>. See the
62 documentation of C<strict> for more details. Not actually new, but
64 Because it is intended for internal use by Perl core components,
65 there is no C<use English> long name for this variable.
69 By default, running out of memory it is not trappable. However, if
70 compiled for this, Perl may use the contents of C<$^M> as an emergency
71 pool after die()ing with this message. Suppose that your Perl were
72 compiled with -DEMERGENCY_SBRK and used Perl's malloc. Then
76 would allocate 64K buffer for use when in emergency.
77 See the F<INSTALL> file for information on how to enable this option.
78 As a disincentive to casual use of this advanced feature,
79 there is no C<use English> long name for this variable.
83 =head2 New and Changed Built-in Functions
87 =item delete on slices
89 This now works. (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
93 is now supported on more platforms, and prefers fcntl
94 to lockf when emulating.
96 =item keys as an lvalue
98 As an lvalue, C<keys> allows you to increase the number of hash buckets
99 allocated for the given associative array. This can gain you a measure
100 of efficiency if you know the hash is going to get big. (This is
101 similar to pre-extending an array by assigning a larger number to
106 then C<%hash> will have at least 200 buckets allocated for it. These
107 buckets will be retained even if you do C<%hash = ()>; use C<undef
108 %hash> if you want to free the storage while C<%hash> is still in scope.
109 You can't shrink the number of buckets allocated for the hash using
110 C<keys> in this way (but you needn't worry about doing this by accident,
111 as trying has no effect).
113 =item my() in Control Structures
115 You can now use my() (with or without the parentheses) in the control
116 expressions of control structures such as:
118 while (my $line = <>) {
124 if ((my $answer = <STDIN>) =~ /^yes$/i) {
126 } elsif ($answer =~ /^no$/i) {
130 die "'$answer' is neither 'yes' nor 'no'";
133 Also, you can declare a foreach loop control variable as lexical by
134 preceding it with the word "my". For example, in:
136 foreach my $i (1, 2, 3) {
140 $i is a lexical variable, and the scope of $i extends to the end of
141 the loop, but not beyond it.
143 Note that you still cannot use my() on global punctuation variables
144 such as $_ and the like.
146 =item unpack() and pack()
148 A new format 'w' represents a BER compressed integer (as defined in
149 ASN.1). Its format is a sequence of one or more bytes, each of which
150 provides seven bits of the total value, with the most significant
151 first. Bit eight of each byte is set, except for the last byte, in
152 which bit eight is clear.
156 If the first argument to C<use> is a number, it is treated as a version
157 number instead of a module name. If the version of the Perl interpreter
158 is less than VERSION, then an error message is printed and Perl exits
159 immediately. This is often useful if you need to check the current
160 Perl version before C<use>ing library modules which have changed in
161 incompatible ways from older versions of Perl. (We try not to do
162 this more than we have to.)
164 =item use Module VERSION LIST
166 If the VERSION argument is present between Module and LIST, then the
167 C<use> will call the VERSION method in class Module with the given
168 version as an argument. The default VERSION method, inherited from
169 the Universal class, croaks if the given version is larger than the
170 value of the variable $Module::VERSION. (Note that there is not a
171 comma after VERSION!)
173 This version-checking mechanism is similar to the one currently used
174 in the Exporter module, but it is faster and can be used with modules
175 that don't use the Exporter. It is the recommended method for new
178 =item prototype(FUNCTION)
180 Returns the prototype of a function as a string (or C<undef> if the
181 function has no prototype). FUNCTION is a reference to or the name of the
182 function whose prototype you want to retrieve.
183 (Not actually new; just never documented before.)
187 Functions documented in the Camel to default to $_ now in
188 fact do, and all those that do are so documented in L<perlfunc>.
190 =head2 C<m//g> does not trigger a pos() reset on failure
192 The C<m//g> match iteration construct used to reset the iteration
193 when it failed to match (so that the next C<m//g> match would start at
194 the beginning of the string). You now have to explicitly do a
195 C<pos $str = 0;> to reset the "last match" position, or modify the
196 string in some way. This change makes it practical to chain C<m//g>
197 matches together in conjunction with ordinary matches using the C<\G>
198 zero-width assertion. See L<perlop> and L<perlre>.
202 =head2 New Built-in Methods
204 The C<UNIVERSAL> package automatically contains the following methods that
205 are inherited by all other classes:
211 C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
213 C<isa> is also exportable and can be called as a sub with two arguments. This
214 allows the ability to check what a reference points to. Example:
216 use UNIVERSAL qw(isa);
218 if(isa($ref, 'ARRAY')) {
224 C<can> checks to see if its object has a method called C<METHOD>,
225 if it does then a reference to the sub is returned; if it does not then
226 I<undef> is returned.
228 =item VERSION( [NEED] )
230 C<VERSION> returns the version number of the class (package). If the
231 NEED argument is given then it will check that the current version (as
232 defined by the $VERSION variable in the given package) not less than
233 NEED; it will die if this is not the case. This method is normally
234 called as a class method. This method is called automatically by the
235 C<VERSION> form of C<use>.
237 use A 1.2 qw(some imported subs);
243 C<class> returns the class name of its object.
247 C<is_instance> returns true if its object is an instance of some
248 class, false if its object is the class (package) itself. Example
250 A->is_instance(); # False
253 $var->is_instance(); # False
255 $ref = bless [], 'A';
256 $ref->is_instance(); # True
260 B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
261 C<isa> uses a very similar method and cache-ing strategy. This may cause
262 strange effects if the Perl code dynamically changes @ISA in any package.
264 You may add other methods to the UNIVERSAL class via Perl or XS code.
265 You do not need to C<use UNIVERSAL> in order to make these methods
266 available to your program. This is necessary only if you wish to
267 have C<isa> available as a plain subroutine in the current package.
269 =head2 TIEHANDLE Now Supported
273 =item TIEHANDLE classname, LIST
275 This is the constructor for the class. That means it is expected to
276 return an object of some sort. The reference can be used to
277 hold some internal information.
279 sub TIEHANDLE { print "<shout>\n"; my $i; bless \$i, shift }
281 =item PRINT this, LIST
283 This method will be triggered every time the tied handle is printed to.
284 Beyond its self reference it also expects the list that was passed to
287 sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
291 This method will be called when the handle is read from. The method
292 should return undef when there is no more data.
294 sub READLINE { $r = shift; "PRINT called $$r times\n"; }
298 As with the other types of ties, this method will be called when the
299 tied handle is about to be destroyed. This is useful for debugging and
300 possibly for cleaning up.
302 sub DESTROY { print "</shout>\n" }
308 Three new pragmatic modules exist:
314 Looks for MakeMaker-like I<'blib'> directory structure starting in
315 I<dir> (or current directory) and working back up to five levels of
318 Intended for use on command line with B<-M> option as a way of testing
319 arbitrary scripts against an uninstalled version of a package.
323 Tells the compiler to enable (or disable) the use of POSIX locales for
326 When C<use locale> is in effect, the current LC_CTYPE locale is used
327 for regular expressions and case mapping; LC_COLLATE for string
328 ordering; and LC_NUMERIC for numeric formating in printf and sprintf
329 (but B<not> in print). LC_NUMERIC is always used in write, since
330 lexical scoping of formats is problematic at best.
332 Each C<use locale> or C<no locale> affects statements to the end of
333 the enclosing BLOCK or, if not inside a BLOCK, to the end of the
334 current file. Locales can be switched and queried with
337 See L<perllocale> for more information.
341 Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
347 =head2 Module Information Summary
351 IO.pm Top-level interface to IO::* classes
352 IO/File.pm IO::File extension Perl module
353 IO/Handle.pm IO::Handle extension Perl module
354 IO/Pipe.pm IO::Pipe extension Perl module
355 IO/Seekable.pm IO::Seekable extension Perl module
356 IO/Select.pm IO::Select extension Perl module
357 IO/Socket.pm IO::Socket extension Perl module
359 Opcode.pm Disable named opcodes when compiling Perl code
361 ExtUtils/Embed.pm Utilities for embedding Perl in C programs
362 ExtUtils/testlib.pm Fixes up @INC to use just-built extension
364 Fatal.pm Make do-or-die equivalents of functions
365 FindBin.pm Find path of currently executing program
367 Class/Template.pm Structure/member template builder
368 File/stat.pm Object-oriented wrapper around CORE::stat
369 Net/hostent.pm Object-oriented wrapper around CORE::gethost*
370 Net/netent.pm Object-oriented wrapper around CORE::getnet*
371 Net/protoent.pm Object-oriented wrapper around CORE::getproto*
372 Net/servent.pm Object-oriented wrapper around CORE::getserv*
373 Time/gmtime.pm Object-oriented wrapper around CORE::gmtime
374 Time/localtime.pm Object-oriented wrapper around CORE::localtime
375 Time/tm.pm Perl implementation of "struct tm" for {gm,local}time
376 User/grent.pm Object-oriented wrapper around CORE::getgr*
377 User/pwent.pm Object-oriented wrapper around CORE::getpw*
379 lib/Tie/RefHash.pm Base class for tied hashes with references as keys
381 UNIVERSAL.pm Base class for *ALL* classes
385 The IO module provides a simple mechanism to load all of the IO modules at one
386 go. Currently this includes:
394 For more information on any of these modules, please see its
395 respective documentation.
399 The Math::Complex module has been totally rewritten, and now supports
400 more operations. These are overloaded:
402 + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
404 And these functions are now exported:
408 tan cotan asin acos atan acotan
409 sinh cosh tanh cotanh asinh acosh atanh acotanh
412 =head2 Overridden Built-ins
414 Many of the Perl built-ins returning lists now have
415 object-oriented overrides. These are:
427 For example, you can now say
431 $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
433 =head1 Efficiency Enhancements
435 All hash keys with the same string are only allocated once, so
436 even if you have 100 copies of the same hash, the immutable keys
437 never have to be re-allocated.
439 Functions that have an empty prototype and that do nothing but return
440 a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
442 =head1 Documentation Changes
444 Many of the base and library pods were updated. These
445 new pods are included in section 1:
455 Locale support (internationalization and localization).
459 Tutorial on Perl OO programming.
463 Perl internal IO abstraction interface.
467 Although not new, this has been massively updated.
471 Although not new, this has been massively updated.
475 =head1 New Diagnostics
477 Several new conditions will trigger warnings that were
478 silent before. Some only affect certain platforms.
479 The following new warnings and errors
484 =item "my" variable %s masks earlier declaration in same scope
486 (S) A lexical variable has been redeclared in the same scope, effectively
487 eliminating all access to the previous instance. This is almost always
488 a typographical error. Note that the earlier variable will still exist
489 until the end of the scope or until all closure referents to it are
492 =item Allocation too large: %lx
494 (X) You can't allocate more than 64K on an MSDOS machine.
496 =item Allocation too large
498 (F) You can't allocate more than 2^31+"small amount" bytes.
500 =item Attempt to free non-existent shared string
502 (P) Perl maintains a reference counted internal table of strings to
503 optimize the storage and access of hash keys and other strings. This
504 indicates someone tried to decrement the reference count of a string
505 that can no longer be found in the table.
507 =item Attempt to use reference as lvalue in substr
509 (W) You supplied a reference as the first argument to substr() used
510 as an lvalue, which is pretty strange. Perhaps you forgot to
511 dereference it first. See L<perlfunc/substr>.
513 =item Unsupported function fork
515 (F) Your version of executable does not support forking.
517 Note that under some systems, like OS/2, there may be different flavors of
518 Perl executables, some of which may support fork, some not. Try changing
519 the name you call Perl by to C<perl_>, C<perl__>, and so on.
521 =item Ill-formed logical name |%s| in prime_env_iter
523 (W) A warning peculiar to VMS. A logical name was encountered when preparing
524 to iterate over %ENV which violates the syntactic rules governing logical
525 names. Since it cannot be translated normally, it is skipped, and will not
526 appear in %ENV. This may be a benign occurrence, as some software packages
527 might directly modify logical name tables and introduce non-standard names,
528 or it may indicate that a logical name table has been corrupted.
530 =item Integer overflow in hex number
532 (S) The literal hex number you have specified is too big for your
533 architecture. On a 32-bit architecture the largest hex literal is
536 =item Integer overflow in octal number
538 (S) The literal octal number you have specified is too big for your
539 architecture. On a 32-bit architecture the largest octal literal is
542 =item Null picture in formline
544 (F) The first argument to formline must be a valid format picture
545 specification. It was found to be empty, which probably means you
546 supplied it an uninitialized value. See L<perlform>.
548 =item Offset outside string
550 (F) You tried to do a read/write/send/recv operation with an offset
551 pointing outside the buffer. This is difficult to imagine.
552 The sole exception to this is that C<sysread()>ing past the buffer
553 will extend the buffer and zero pad the new area.
557 (X|F) The malloc() function returned 0, indicating there was insufficient
558 remaining memory (or virtual memory) to satisfy the request.
560 The request was judged to be small, so the possibility to trap it
561 depends on the way Perl was compiled. By default it is not trappable.
562 However, if compiled for this, Perl may use the contents of C<$^M> as
563 an emergency pool after die()ing with this message. In this case the
564 error is trappable I<once>.
566 =item Out of memory during request for %s
568 (F) The malloc() function returned 0, indicating there was insufficient
569 remaining memory (or virtual memory) to satisfy the request. However,
570 the request was judged large enough (compile-time default is 64K), so
571 a possibility to shut down by trapping this error is granted.
573 =item Possible attempt to put comments in qw() list
575 (W) You probably wrote something like this:
581 when you should have written this:
587 =item Possible attempt to separate words with commas
589 (W) You probably wrote something like this:
593 when you should have written this:
597 =item untie attempted while %d inner references still exist
599 (W) A copy of the object returned from C<tie> (or C<tied>) was still
600 valid when C<untie> was called.
602 =item Got an error from DosAllocMem:
604 (P) An error peculiar to OS/2. Most probably you use an obsolete version
605 of Perl, and should not happen anyway.
607 =item Malformed PERLLIB_PREFIX
609 (F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
617 with non-empty prefix1 and prefix2. If C<prefix1> is indeed a prefix of
618 a builtin library search path, prefix2 is substituted. The error may appear
619 if components are not found, or are too long. See L<perlos2/"PERLLIB_PREFIX">.
621 =item PERL_SH_DIR too long
623 (F) An error peculiar to OS/2. PERL_SH_DIR is the directory to find the
624 C<sh>-shell in. See L<perlos2/"PERL_SH_DIR">.
626 =item Process terminated by SIG%s
628 (W) This is a standard message issued by OS/2 applications, while *nix
629 applications die in silence. It is considered a feature of the OS/2
630 port. One can easily disable this by appropriate sighandlers, see
631 L<perlipc/"Signals">. See L<perlos2/"Process terminated by SIGTERM/SIGINT">.
637 If you find what you think is a bug, you might check the headers
638 of recently posted articles
639 in the comp.lang.perl.misc newsgroup. There may also be
640 information at http://www.perl.com/perl/, the Perl Home Page.
642 If you believe you have an unreported bug, please run the B<perlbug>
643 program included with your release. Make sure you trim your bug
644 down to a tiny but sufficient test case. Your bug report, along
645 with the output of C<perl -V>, will be sent off to perlbug@perl.com
646 to be analysed by the Perl porting team.
650 The F<Changes> file for exhaustive details on what changed.
652 The F<INSTALL> file for how to build Perl. This file has been
653 significantly updated for 5.004, so even veteran users should
656 The F<README> file for general stuff.
658 The F<Copying> file for copyright information.
662 Constructed by Tom Christiansen, grabbing material with permission
663 from innumerable contributors, with kibitzing by more than a few Perl
666 Last update: Tue Dec 24 16:45:14 EST 1996