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.
28 =head2 New Opcode Module and Revised Safe Module
30 A new Opcode module supports the creation, manipulation and
31 application of opcode masks. The revised Safe module has a new API
32 and is implemented using the new Opcode module. Please read the new
33 Opcode and Safe documentation.
35 =head2 Internal Change: FileHandle Deprecated
37 Filehandles are now stored internally as type IO::Handle.
38 Although C<use FileHandle> and C<*STDOUT{FILEHANDLE}>
39 are still supported for backwards compatibility
40 C<use IO::Handle> (or C<IO::Seekable> or C<IO::File>) and
41 C<*STDOUT{IO}> are the way of the future.
43 =head2 Internal Change: PerlIO internal IO abstraction interface.
45 It is now possible to build Perl with AT&T's sfio IO package
46 instead of stdio. See L<perlapio> for more details, and
47 the F<INSTALL> file for how to use it.
49 =head2 New and Changed Built-in Variables
55 Extended error message under some platforms ($EXTENDED_OS_ERROR
56 if you C<use English>).
60 The current set of syntax checks enabled by C<use strict>. See the
61 documentation of C<strict> for more details. Not actually new, but
63 Because it is intended for internal use by Perl core components,
64 there is no C<use English> long name for this variable.
68 By default, running out of memory it is not trappable. However, if
69 compiled for this, Perl may use the contents of C<$^M> as an emergency
70 pool after die()ing with this message. Suppose that your Perl were
71 compiled with -DEMERGENCY_SBRK and used Perl's malloc. Then
75 would allocate 64K buffer for use when in emergency.
76 See the F<INSTALL> file for information on how to enable this option.
77 As a disincentive to casual use of this advanced feature,
78 there is no C<use English> long name for this variable.
82 =head2 New and Changed Built-in Functions
86 =item delete on slices
88 This now works. (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
92 is now supported on more platforms, and prefers fcntl
93 to lockf when emulating.
95 =item keys as an lvalue
97 As an lvalue, C<keys> allows you to increase the number of hash buckets
98 allocated for the given associative array. This can gain you a measure
99 of efficiency if you know the hash is going to get big. (This is
100 similar to pre-extending an array by assigning a larger number to
105 then C<%hash> will have at least 200 buckets allocated for it. These
106 buckets will be retained even if you do C<%hash = ()>; use C<undef
107 %hash> if you want to free the storage while C<%hash> is still in scope.
108 You can't shrink the number of buckets allocated for the hash using
109 C<keys> in this way (but you needn't worry about doing this by accident,
110 as trying has no effect).
112 =item my() in Control Structures
114 You can now use my() (with or without the parentheses) in the control
115 expressions of control structures such as:
117 while (my $line = <>) {
123 if ((my $answer = <STDIN>) =~ /^yes$/i) {
125 } elsif ($answer =~ /^no$/i) {
129 die "'$answer' is neither 'yes' nor 'no'";
132 Also, you can declare a foreach loop control variable as lexical by
133 preceding it with the word "my". For example, in:
135 foreach my $i (1, 2, 3) {
139 $i is a lexical variable, and the scope of $i extends to the end of
140 the loop, but not beyond it.
142 Note that you still cannot use my() on global punctuation variables
143 such as $_ and the like.
145 =item unpack() and pack()
147 A new format 'w' represents a BER compressed integer (as defined in
148 ASN.1). Its format is a sequence of one or more bytes, each of which
149 provides seven bits of the total value, with the most significant
150 first. Bit eight of each byte is set, except for the last byte, in
151 which bit eight is clear.
155 If the first argument to C<use> is a number, it is treated as a version
156 number instead of a module name. If the version of the Perl interpreter
157 is less than VERSION, then an error message is printed and Perl exits
158 immediately. This is often useful if you need to check the current
159 Perl version before C<use>ing library modules which have changed in
160 incompatible ways from older versions of Perl. (We try not to do
161 this more than we have to.)
163 =item use Module VERSION LIST
165 If the VERSION argument is present between Module and LIST, then the
166 C<use> will call the VERSION method in class Module with the given
167 version as an argument. The default VERSION method, inherited from
168 the Universal class, croaks if the given version is larger than the
169 value of the variable $Module::VERSION. (Note that there is not a
170 comma after VERSION!)
172 This version-checking mechanism is similar to the one currently used
173 in the Exporter module, but it is faster and can be used with modules
174 that don't use the Exporter. It is the recommended method for new
177 =item prototype(FUNCTION)
179 Returns the prototype of a function as a string (or C<undef> if the
180 function has no prototype). FUNCTION is a reference to or the name of the
181 function whose prototype you want to retrieve.
182 (Not actually new; just never documented before.)
186 Functions documented in the Camel to default to $_ now in
187 fact do, and all those that do are so documented in L<perlfunc>.
191 =head2 New Built-in Methods
193 The C<UNIVERSAL> package automatically contains the following methods that
194 are inherited by all other classes:
200 C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
202 C<isa> is also exportable and can be called as a sub with two arguments. This
203 allows the ability to check what a reference points to. Example:
205 use UNIVERSAL qw(isa);
207 if(isa($ref, 'ARRAY')) {
213 C<can> checks to see if its object has a method called C<METHOD>,
214 if it does then a reference to the sub is returned; if it does not then
215 I<undef> is returned.
217 =item VERSION( [NEED] )
219 C<VERSION> returns the version number of the class (package). If the
220 NEED argument is given then it will check that the current version (as
221 defined by the $VERSION variable in the given package) not less than
222 NEED; it will die if this is not the case. This method is normally
223 called as a class method. This method is called automatically by the
224 C<VERSION> form of C<use>.
226 use A 1.2 qw(some imported subs);
232 C<class> returns the class name of its object.
236 C<is_instance> returns true if its object is an instance of some
237 class, false if its object is the class (package) itself. Example
239 A->is_instance(); # False
242 $var->is_instance(); # False
244 $ref = bless [], 'A';
245 $ref->is_instance(); # True
249 B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
250 C<isa> uses a very similar method and cache-ing strategy. This may cause
251 strange effects if the Perl code dynamically changes @ISA in any package.
253 You may add other methods to the UNIVERSAL class via Perl or XS code.
254 You do not need to C<use UNIVERSAL> in order to make these methods
255 available to your program. This is necessary only if you wish to
256 have C<isa> available as a plain subroutine in the current package.
258 =head2 TIEHANDLE Now Supported
262 =item TIEHANDLE classname, LIST
264 This is the constructor for the class. That means it is expected to
265 return an object of some sort. The reference can be used to
266 hold some internal information.
268 sub TIEHANDLE { print "<shout>\n"; my $i; bless \$i, shift }
270 =item PRINT this, LIST
272 This method will be triggered every time the tied handle is printed to.
273 Beyond its self reference it also expects the list that was passed to
276 sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
280 This method will be called when the handle is read from. The method
281 should return undef when there is no more data.
283 sub READLINE { $r = shift; "PRINT called $$r times\n"; }
287 As with the other types of ties, this method will be called when the
288 tied handle is about to be destroyed. This is useful for debugging and
289 possibly for cleaning up.
291 sub DESTROY { print "</shout>\n" }
297 Three new pragmatic modules exist:
303 Looks for MakeMaker-like I<'blib'> directory structure starting in
304 I<dir> (or current directory) and working back up to five levels of
307 Intended for use on command line with B<-M> option as a way of testing
308 arbitrary scripts against an uninstalled version of a package.
312 Tells the compiler to enable (or disable) the use of POSIX locales for
315 When C<use locale> is in effect, the current LC_CTYPE locale is used
316 for regular expressions and case mapping; LC_COLLATE for string
317 ordering; and LC_NUMERIC for numeric formating in printf and sprintf
318 (but B<not> in print). LC_NUMERIC is always used in write, since
319 lexical scoping of formats is problematic at best.
321 Each C<use locale> or C<no locale> affects statements to the end of
322 the enclosing BLOCK or, if not inside a BLOCK, to the end of the
323 current file. Locales can be switched and queried with
326 See L<perllocale> for more information.
330 Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
336 =head2 Module Information Summary
340 IO.pm Top-level interface to IO::* classes
341 IO/File.pm IO::File extension Perl module
342 IO/Handle.pm IO::Handle extension Perl module
343 IO/Pipe.pm IO::Pipe extension Perl module
344 IO/Seekable.pm IO::Seekable extension Perl module
345 IO/Select.pm IO::Select extension Perl module
346 IO/Socket.pm IO::Socket extension Perl module
348 Opcode.pm Disable named opcodes when compiling Perl code
350 ExtUtils/Embed.pm Utilities for embedding Perl in C programs
351 ExtUtils/testlib.pm Fixes up @INC to use just-built extension
353 Fatal.pm Make do-or-die equivalents of functions
354 FindBin.pm Find path of currently executing program
356 Class/Template.pm Structure/member template builder
357 File/stat.pm Object-oriented wrapper around CORE::stat
358 Net/hostent.pm Object-oriented wrapper around CORE::gethost*
359 Net/netent.pm Object-oriented wrapper around CORE::getnet*
360 Net/protoent.pm Object-oriented wrapper around CORE::getproto*
361 Net/servent.pm Object-oriented wrapper around CORE::getserv*
362 Time/gmtime.pm Object-oriented wrapper around CORE::gmtime
363 Time/localtime.pm Object-oriented wrapper around CORE::localtime
364 Time/tm.pm Perl implementation of "struct tm" for {gm,local}time
365 User/grent.pm Object-oriented wrapper around CORE::getgr*
366 User/pwent.pm Object-oriented wrapper around CORE::getpw*
368 lib/Tie/RefHash.pm Base class for tied hashes with references as keys
370 UNIVERSAL.pm Base class for *ALL* classes
374 The IO module provides a simple mechanism to load all of the IO modules at one
375 go. Currently this includes:
383 For more information on any of these modules, please see its
384 respective documentation.
388 The Math::Complex module has been totally rewritten, and now supports
389 more operations. These are overloaded:
391 + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
393 And these functions are now exported:
397 tan cotan asin acos atan acotan
398 sinh cosh tanh cotanh asinh acosh atanh acotanh
401 =head2 Overridden Built-ins
403 Many of the Perl built-ins returning lists now have
404 object-oriented overrides. These are:
416 For example, you can now say
420 $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
422 =head1 Efficiency Enhancements
424 All hash keys with the same string are only allocated once, so
425 even if you have 100 copies of the same hash, the immutable keys
426 never have to be re-allocated.
428 Functions that have an empty prototype and that do nothing but return
429 a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
431 =head1 Documentation Changes
433 Many of the base and library pods were updated. These
434 new pods are included in section 1:
444 Locale support (internationalization and localization).
448 Tutorial on Perl OO programming.
452 Perl internal IO abstraction interface.
456 Although not new, this has been massively updated.
460 Although not new, this has been massively updated.
464 =head1 New Diagnostics
466 Several new conditions will trigger warnings that were
467 silent before. Some only affect certain platforms.
468 The following new warnings and errors
473 =item "my" variable %s masks earlier declaration in same scope
475 (S) A lexical variable has been redeclared in the same scope, effectively
476 eliminating all access to the previous instance. This is almost always
477 a typographical error. Note that the earlier variable will still exist
478 until the end of the scope or until all closure referents to it are
481 =item Allocation too large: %lx
483 (X) You can't allocate more than 64K on an MSDOS machine.
485 =item Allocation too large
487 (F) You can't allocate more than 2^31+"small amount" bytes.
489 =item Attempt to free non-existent shared string
491 (P) Perl maintains a reference counted internal table of strings to
492 optimize the storage and access of hash keys and other strings. This
493 indicates someone tried to decrement the reference count of a string
494 that can no longer be found in the table.
496 =item Attempt to use reference as lvalue in substr
498 (W) You supplied a reference as the first argument to substr() used
499 as an lvalue, which is pretty strange. Perhaps you forgot to
500 dereference it first. See L<perlfunc/substr>.
502 =item Unsupported function fork
504 (F) Your version of executable does not support forking.
506 Note that under some systems, like OS/2, there may be different flavors of
507 Perl executables, some of which may support fork, some not. Try changing
508 the name you call Perl by to C<perl_>, C<perl__>, and so on.
510 =item Ill-formed logical name |%s| in prime_env_iter
512 (W) A warning peculiar to VMS. A logical name was encountered when preparing
513 to iterate over %ENV which violates the syntactic rules governing logical
514 names. Since it cannot be translated normally, it is skipped, and will not
515 appear in %ENV. This may be a benign occurrence, as some software packages
516 might directly modify logical name tables and introduce non-standard names,
517 or it may indicate that a logical name table has been corrupted.
519 =item Integer overflow in hex number
521 (S) The literal hex number you have specified is too big for your
522 architecture. On a 32-bit architecture the largest hex literal is
525 =item Integer overflow in octal number
527 (S) The literal octal number you have specified is too big for your
528 architecture. On a 32-bit architecture the largest octal literal is
531 =item Null picture in formline
533 (F) The first argument to formline must be a valid format picture
534 specification. It was found to be empty, which probably means you
535 supplied it an uninitialized value. See L<perlform>.
537 =item Offset outside string
539 (F) You tried to do a read/write/send/recv operation with an offset
540 pointing outside the buffer. This is difficult to imagine.
541 The sole exception to this is that C<sysread()>ing past the buffer
542 will extend the buffer and zero pad the new area.
546 (X|F) The malloc() function returned 0, indicating there was insufficient
547 remaining memory (or virtual memory) to satisfy the request.
549 The request was judged to be small, so the possibility to trap it
550 depends on the way Perl was compiled. By default it is not trappable.
551 However, if compiled for this, Perl may use the contents of C<$^M> as
552 an emergency pool after die()ing with this message. In this case the
553 error is trappable I<once>.
555 =item Out of memory during request for %s
557 (F) The malloc() function returned 0, indicating there was insufficient
558 remaining memory (or virtual memory) to satisfy the request. However,
559 the request was judged large enough (compile-time default is 64K), so
560 a possibility to shut down by trapping this error is granted.
562 =item Possible attempt to put comments in qw() list
564 (W) You probably wrote something like this:
570 when you should have written this:
576 =item Possible attempt to separate words with commas
578 (W) You probably wrote something like this:
582 when you should have written this:
586 =item untie attempted while %d inner references still exist
588 (W) A copy of the object returned from C<tie> (or C<tied>) was still
589 valid when C<untie> was called.
591 =item Got an error from DosAllocMem:
593 (P) An error peculiar to OS/2. Most probably you use an obsolete version
594 of Perl, and should not happen anyway.
596 =item Malformed PERLLIB_PREFIX
598 (F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
606 with non-empty prefix1 and prefix2. If C<prefix1> is indeed a prefix of
607 a builtin library search path, prefix2 is substituted. The error may appear
608 if components are not found, or are too long. See L<perlos2/"PERLLIB_PREFIX">.
610 =item PERL_SH_DIR too long
612 (F) An error peculiar to OS/2. PERL_SH_DIR is the directory to find the
613 C<sh>-shell in. See L<perlos2/"PERL_SH_DIR">.
615 =item Process terminated by SIG%s
617 (W) This is a standard message issued by OS/2 applications, while *nix
618 applications die in silence. It is considered a feature of the OS/2
619 port. One can easily disable this by appropriate sighandlers, see
620 L<perlipc/"Signals">. See L<perlos2/"Process terminated by SIGTERM/SIGINT">.
626 If you find what you think is a bug, you might check the headers
627 of recently posted articles
628 in the comp.lang.perl.misc newsgroup. There may also be
629 information at http://www.perl.com/perl/, the Perl Home Page.
631 If you believe you have an unreported bug, please run the B<perlbug>
632 program included with your release. Make sure you trim your bug
633 down to a tiny but sufficient test case. Your bug report, along
634 with the output of C<perl -V>, will be sent off to perlbug@perl.com
635 to be analysed by the Perl porting team.
639 The F<Changes> file for exhaustive details on what changed.
641 The F<INSTALL> file for how to build Perl. This file has been
642 significantly updated for 5.004, so even veteran users should
645 The F<README> file for general stuff.
647 The F<Copying> file for copyright information.
651 Constructed by Tom Christiansen, grabbing material with permission
652 from innumerable contributors, with kibitzing by more than a few Perl
655 Last update: Tue Dec 24 16:45:14 EST 1996