This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix overloading via inherited autoloaded functions
[perl5.git] / pod / perlnews.pod
1 =head1 NAME
2
3 perlnews - what's new for perl5.004
4
5 =head1 DESCRIPTION
6
7 This document describes differences between the 5.003 release (as
8 documented in I<Programming Perl>, second edition--the Camel Book) and
9 this one.
10
11 =head1 Supported Environments
12
13 Perl5.004 builds out of the box on Unix, Plan9, LynxOS, VMS, OS/2,
14 QNX, and AmigaOS.
15
16 =head1 Core Changes
17
18 Most importantly, many bugs were fixed.  See the F<Changes>
19 file in the distribution for details.
20
21 =head2 Compilation Option: Binary Compatibility With 5.003
22
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.
28
29 =head2 New Opcode Module and Revised Safe Module
30
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.
35
36 =head2 Internal Change: FileHandle Deprecated
37
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.
43
44 =head2 Internal Change: PerlIO internal IO abstraction interface
45
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.
49
50 =head2 New and Changed Built-in Variables
51
52 =over
53
54 =item $^E
55
56 Extended error message under some platforms ($EXTENDED_OS_ERROR
57 if you C<use English>).
58
59 =item $^H
60
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
63 newly documented.
64 Because it is intended for internal use by Perl core components,
65 there is no C<use English> long name for this variable.
66
67 =item $^M
68
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
73
74     $^M = 'a' x (1<<16);
75
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.
80
81 =back
82
83 =head2 New and Changed Built-in Functions
84
85 =over
86
87 =item delete on slices
88
89 This now works.  (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
90
91 =item flock
92
93 is now supported on more platforms, and prefers fcntl
94 to lockf when emulating.
95
96 =item keys as an lvalue
97
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
102 $#array.)  If you say
103
104     keys %hash = 200;
105
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).
112
113 =item my() in Control Structures
114
115 You can now use my() (with or without the parentheses) in the control
116 expressions of control structures such as:
117
118     while (my $line = <>) {
119         $line = lc $line;
120     } continue {
121         print $line;
122     }
123
124     if ((my $answer = <STDIN>) =~ /^yes$/i) {
125         user_agrees();
126     } elsif ($answer =~ /^no$/i) {
127         user_disagrees();
128     } else {
129         chomp $answer;
130         die "'$answer' is neither 'yes' nor 'no'";
131     }
132
133 Also, you can declare a foreach loop control variable as lexical by
134 preceding it with the word "my".  For example, in:
135
136     foreach my $i (1, 2, 3) {
137         some_function();
138     }
139
140 $i is a lexical variable, and the scope of $i extends to the end of
141 the loop, but not beyond it.
142
143 Note that you still cannot use my() on global punctuation variables
144 such as $_ and the like.
145
146 =item unpack() and pack()
147
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.
153
154 =item use VERSION
155
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.)
163
164 =item use Module VERSION LIST
165
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!)
172
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
176 code.
177
178 =item prototype(FUNCTION)
179
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.)
184
185 =item $_ as Default
186
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>.
189
190 =head2 C<m//g> does not trigger a pos() reset on failure
191
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>.
199
200 =back
201
202 =head2 New Built-in Methods
203
204 The C<UNIVERSAL> package automatically contains the following methods that
205 are inherited by all other classes:
206
207 =over 4
208
209 =item isa(CLASS)
210
211 C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
212
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:
215
216     use UNIVERSAL qw(isa);
217
218     if(isa($ref, 'ARRAY')) {
219        ...
220     }
221
222 =item can(METHOD)
223
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.
227
228 =item VERSION( [NEED] )
229
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>.
236
237     use A 1.2 qw(some imported subs);
238     # implies:
239     A->VERSION(1.2);
240
241 =item class()
242
243 C<class> returns the class name of its object.
244
245 =item is_instance()
246
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
249
250     A->is_instance();       # False
251
252     $var = 'A';
253     $var->is_instance();    # False
254
255     $ref = bless [], 'A';
256     $ref->is_instance();    # True
257
258 =back
259
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.
263
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.
268
269 =head2 TIEHANDLE Now Supported
270
271 =over
272
273 =item TIEHANDLE classname, LIST
274
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.
278
279     sub TIEHANDLE { print "<shout>\n"; my $i; bless \$i, shift }
280
281 =item PRINT this, LIST
282
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
285 the print function.
286
287     sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
288
289 =item READLINE this
290
291 This method will be called when the handle is read from. The method
292 should return undef when there is no more data.
293
294     sub READLINE { $r = shift; "PRINT called $$r times\n"; }
295
296 =item DESTROY this
297
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.
301
302     sub DESTROY { print "</shout>\n" }
303
304 =back
305
306 =head1 Pragmata
307
308 Three new pragmatic modules exist:
309
310 =over
311
312 =item use blib
313
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
316 parent directories.
317
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.
320
321 =item use locale
322
323 Tells the compiler to enable (or disable) the use of POSIX locales for
324 built-in operations.
325
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.
331
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
335 POSIX::setlocale().
336
337 See L<perllocale> for more information.
338
339 =item use ops
340
341 Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
342
343 =back
344
345 =head1 Modules
346
347 =head2 Module Information Summary
348
349 Brand new modules:
350
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
358
359     Opcode.pm            Disable named opcodes when compiling Perl code
360
361     ExtUtils/Embed.pm    Utilities for embedding Perl in C programs
362     ExtUtils/testlib.pm  Fixes up @INC to use just-built extension
363
364     Fatal.pm             Make do-or-die equivalents of functions
365     FindBin.pm           Find path of currently executing program
366
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*
378
379     lib/Tie/RefHash.pm   Base class for tied hashes with references as keys
380
381     UNIVERSAL.pm         Base class for *ALL* classes
382
383 =head2 IO
384
385 The IO module provides a simple mechanism to load all of the IO modules at one
386 go.  Currently this includes:
387
388      IO::Handle
389      IO::Seekable
390      IO::File
391      IO::Pipe
392      IO::Socket
393
394 For more information on any of these modules, please see its
395 respective documentation.
396
397 =head2 Math::Complex
398
399 The Math::Complex module has been totally rewritten, and now supports
400 more operations.  These are overloaded:
401
402      + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
403
404 And these functions are now exported:
405
406     pi i Re Im arg
407     log10 logn cbrt root
408     tan cotan asin acos atan acotan
409     sinh cosh tanh cotanh asinh acosh atanh acotanh
410     cplx cplxe
411
412 =head2 Overridden Built-ins
413
414 Many of the Perl built-ins returning lists now have
415 object-oriented overrides.  These are:
416
417     File::stat
418     Net::hostent
419     Net::netent
420     Net::protoent
421     Net::servent
422     Time::gmtime
423     Time::localtime
424     User::grent
425     User::pwent
426
427 For example, you can now say
428
429     use File::stat;
430     use User::pwent;
431     $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
432
433 =head1 Efficiency Enhancements
434
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.
438
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 }>).
441
442 =head1 Documentation Changes
443
444 Many of the base and library pods were updated.  These
445 new pods are included in section 1:
446
447 =over 4
448
449 =item L<perlnews>
450
451 This document.
452
453 =item L<perllocale>
454
455 Locale support (internationalization and localization).
456
457 =item L<perltoot>
458
459 Tutorial on Perl OO programming.
460
461 =item L<perlapio>
462
463 Perl internal IO abstraction interface.
464
465 =item L<perldebug>
466
467 Although not new, this has been massively updated.
468
469 =item L<perlsec>
470
471 Although not new, this has been massively updated.
472
473 =back
474
475 =head1 New Diagnostics
476
477 Several new conditions will trigger warnings that were
478 silent before.  Some only affect certain platforms.
479 The following new warnings and errors
480 outline these:
481
482 =over 4
483
484 =item "my" variable %s masks earlier declaration in same scope
485
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
490 destroyed.
491
492 =item Allocation too large: %lx
493
494 (X) You can't allocate more than 64K on an MSDOS machine.
495
496 =item Allocation too large
497
498 (F) You can't allocate more than 2^31+"small amount" bytes.
499
500 =item Attempt to free non-existent shared string
501
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.
506
507 =item Attempt to use reference as lvalue in substr
508
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>.
512
513 =item Unsupported function fork
514
515 (F) Your version of executable does not support forking.
516
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.
520
521 =item Ill-formed logical name |%s| in prime_env_iter
522
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.
529
530 =item Integer overflow in hex number
531
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
534 0xFFFFFFFF.
535
536 =item Integer overflow in octal number
537
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
540 037777777777.
541
542 =item Null picture in formline
543
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>.
547
548 =item Offset outside string
549
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.
554
555 =item Out of memory!
556
557 (X|F) The malloc() function returned 0, indicating there was insufficient
558 remaining memory (or virtual memory) to satisfy the request.
559
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>.
565
566 =item Out of memory during request for %s
567
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.
572
573 =item Possible attempt to put comments in qw() list
574
575 (W) You probably wrote something like this:
576
577     qw( a # a comment
578         b # another comment
579       ) ;
580
581 when you should have written this:
582
583     qw( a
584         b
585       ) ;
586
587 =item Possible attempt to separate words with commas
588
589 (W) You probably wrote something like this:
590
591     qw( a, b, c );
592
593 when you should have written this:
594
595     qw( a b c );
596
597 =item untie attempted while %d inner references still exist
598
599 (W) A copy of the object returned from C<tie> (or C<tied>) was still
600 valid when C<untie> was called.
601
602 =item Got an error from DosAllocMem:
603
604 (P) An error peculiar to OS/2. Most probably you use an obsolete version
605 of Perl, and should not happen anyway.
606
607 =item Malformed PERLLIB_PREFIX
608
609 (F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
610
611     prefix1;prefix2
612
613 or
614
615     prefix1 prefix2
616
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">.
620
621 =item PERL_SH_DIR too long
622
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">.
625
626 =item Process terminated by SIG%s
627
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">.
632
633 =back
634
635 =head1 BUGS
636
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.
641
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.
647
648 =head1 SEE ALSO
649
650 The F<Changes> file for exhaustive details on what changed.
651
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
654 look through it.
655
656 The F<README> file for general stuff.
657
658 The F<Copying> file for copyright information.
659
660 =head1 HISTORY
661
662 Constructed by Tom Christiansen, grabbing material with permission
663 from innumerable contributors, with kibitzing by more than a few Perl
664 porters.
665
666 Last update: Tue Dec 24 16:45:14 EST 1996