[inseparable changes from patch from perl5.003_12 to perl5.003_13]
[p5sagit/p5-mst-13.2.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
28 =head2 Internal Change: FileHandle Deprecated
29
30 Filehandles are now stored internally as type IO::Handle.
31 Although C<use FileHandle> and C<*STDOUT{FILEHANDLE}>
32 are still supported for backwards compatibility
33 C<use IO::Handle> (or C<IO::Seekable> or C<IO::File>) and
34 C<*STDOUT{IO}> are the way of the future.
35
36 =head2 Internal Change: Safe Module Absorbed into Opcode
37
38 A new Opcode module subsumes 5.003's Safe module.  The Safe
39 interface is still available, so existing scripts should still
40 work, but users are encouraged to read the new Opcode documentation.
41
42 =head2 Internal Change: PerlIO internal IO abstraction interface.
43
44 It is now possible to build Perl with AT&T's sfio IO package
45 instead of stdio.  See L<perlapio> for more details, and
46 the F<INSTALL> file for how to use it.
47
48 =head2 New and Changed Built-in Variables
49
50 =over
51
52 =item $^E
53
54 Extended error message under some platforms ($EXTENDED_OS_ERROR
55 if you C<use English>).
56
57 =item $^H
58
59 The current set of syntax checks enabled by C<use strict>.  See the
60 documentation of C<strict> for more details.  Not actually new, but
61 newly documented.
62 Because it is intended for internal use by Perl core components,
63 there is no C<use English> long name for this variable.
64
65 =item $^M
66
67 By default, running out of memory it is not trappable.  However, if
68 compiled for this, Perl may use the contents of C<$^M> as an emergency
69 pool after die()ing with this message.  Suppose that your Perl were
70 compiled with -DEMERGENCY_SBRK and used Perl's malloc.  Then
71
72     $^M = 'a' x (1<<16);
73
74 would allocate 64K buffer for use when in emergency.
75 See the F<INSTALL> file for information on how to enable this option.
76 As a disincentive to casual use of this advanced feature,
77 there is no C<use English> long name for this variable.
78
79 =back
80
81 =head2 New and Changed Built-in Functions
82
83 =over
84
85 =item delete on slices
86
87 This now works.  (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
88
89 =item flock
90
91 is now supported on more platforms, and prefers fcntl
92 to lockf when emulating.
93
94 =item keys as an lvalue
95
96 As an lvalue, C<keys> allows you to increase the number of hash buckets
97 allocated for the given associative array.  This can gain you a measure
98 of efficiency if you know the hash is going to get big.  (This is
99 similar to pre-extending an array by assigning a larger number to
100 $#array.)  If you say
101
102     keys %hash = 200;
103
104 then C<%hash> will have at least 200 buckets allocated for it.  These
105 buckets will be retained even if you do C<%hash = ()>; use C<undef
106 %hash> if you want to free the storage while C<%hash> is still in scope.
107 You can't shrink the number of buckets allocated for the hash using
108 C<keys> in this way (but you needn't worry about doing this by accident,
109 as trying has no effect).
110
111 =item my() in Control Structures
112
113 You can now use my() (with or without the parentheses) in the control
114 expressions of control structures such as:
115
116     while (my $line = <>) {
117         $line = lc $line;
118     } continue {
119         print $line;
120     }
121
122     if ((my $answer = <STDIN>) =~ /^yes$/i) {
123         user_agrees();
124     } elsif ($answer =~ /^no$/i) {
125         user_disagrees();
126     } else {
127         chomp $answer;
128         die "'$answer' is neither 'yes' nor 'no'";
129     }
130
131 Also, you can declare a foreach loop control variable as lexical by
132 preceding it with the word "my".  For example, in:
133
134     foreach my $i (1, 2, 3) {
135         some_function();
136     }
137
138 $i is a lexical variable, and the scope of $i extends to the end of
139 the loop, but not beyond it.
140
141 Note that you still cannot use my() on global punctuation variables
142 such as $_ and the like.
143
144 =item unpack() and pack()
145
146 A new format 'w' represents a BER compressed integer (as defined in
147 ASN.1).  Its format is a sequence of one or more bytes, each of which
148 provides seven bits of the total value, with the most significant
149 first.  Bit eight of each byte is set, except for the last byte, in
150 which bit eight is clear.
151
152 =item use VERSION
153
154 If the first argument to C<use> is a number, it is treated as a version
155 number instead of a module name.  If the version of the Perl interpreter
156 is less than VERSION, then an error message is printed and Perl exits
157 immediately.  This is often useful if you need to check the current
158 Perl version before C<use>ing library modules which have changed in
159 incompatible ways from older versions of Perl.  (We try not to do
160 this more than we have to.)
161
162 =item use Module VERSION LIST
163
164 If the VERSION argument is present between Module and LIST, then the
165 C<use> will fail if the $VERSION variable in package Module is
166 less than VERSION.
167
168 Note that there is not a comma after the version!
169
170 =item prototype(FUNCTION)
171
172 Returns the prototype of a function as a string (or C<undef> if the
173 function has no prototype).  FUNCTION is a reference to or the name of the
174 function whose prototype you want to retrieve.
175 (Not actually new; just never documented before.)
176
177 =item $_ as Default
178
179 Functions documented in the Camel to default to $_ now in
180 fact do, and all those that do are so documented in L<perlfunc>.
181
182 =back
183
184 =head2 New Built-in Methods
185
186 The C<UNIVERSAL> package automatically contains the following methods that
187 are inherited by all other classes:
188
189 =over 4
190
191 =item isa(CLASS)
192
193 C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
194
195 C<isa> is also exportable and can be called as a sub with two arguments. This
196 allows the ability to check what a reference points to. Example:
197
198     use UNIVERSAL qw(isa);
199
200     if(isa($ref, 'ARRAY')) {
201        ...
202     }
203
204 =item can(METHOD)
205
206 C<can> checks to see if its object has a method called C<METHOD>,
207 if it does then a reference to the sub is returned; if it does not then
208 I<undef> is returned.
209
210 =item VERSION( [NEED] )
211
212 C<VERSION> returns the version number of the class (package). If the
213 NEED argument is given then it will check that the current version is
214 not less than NEED and die if this is not the case. This method is
215 normally called as a class method. This method is also called when the
216 C<VERSION> form of C<use> is used.
217
218     use A 1.2 qw(some imported subs);
219
220     A->VERSION( 1.2 );
221     $ref->is_instance();    # True
222
223 =item class()
224
225 C<class> returns the class name of its object.
226
227 =item is_instance()
228
229 C<is_instance> returns true if its object is an instance of some
230 class, false if its object is the class (package) itself. Example
231
232     A->is_instance();       # False
233
234     $var = 'A';
235     $var->is_instance();    # False
236
237     $ref = bless [], 'A';
238     $ref->is_instance();    # True
239
240 =back
241
242 B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
243 C<isa> uses a very similar method and cache-ing strategy. This may cause
244 strange effects if the Perl code dynamically changes @ISA in any package.
245
246 You may add other methods to the UNIVERSAL class via Perl or XS code.
247 You do not need to C<use UNIVERSAL> in order to make these methods
248 available to your program.  This is necessary only if you wish to
249 have C<isa> available as a plain subroutine in the current package.
250
251 =head2 TIEHANDLE Now Supported
252
253 =over
254
255 =item TIEHANDLE classname, LIST
256
257 This is the constructor for the class.  That means it is expected to
258 return an object of some sort. The reference can be used to
259 hold some internal information.
260
261     sub TIEHANDLE { print "<shout>\n"; my $i; bless \$i, shift }
262
263 =item PRINT this, LIST
264
265 This method will be triggered every time the tied handle is printed to.
266 Beyond its self reference it also expects the list that was passed to
267 the print function.
268
269     sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
270
271 =item READLINE this
272
273 This method will be called when the handle is read from. The method
274 should return undef when there is no more data.
275
276     sub READLINE { $r = shift; "PRINT called $$r times\n"; }
277
278 =item DESTROY this
279
280 As with the other types of ties, this method will be called when the
281 tied handle is about to be destroyed. This is useful for debugging and
282 possibly for cleaning up.
283
284     sub DESTROY { print "</shout>\n" }
285
286 =back
287
288 =head1 Pragmata
289
290 Three new pragmatic modules exist:
291
292 =over
293
294 =item use blib
295
296 Looks for MakeMaker-like I<'blib'> directory structure starting in
297 I<dir> (or current directory) and working back up to five levels of
298 parent directories.
299
300 Intended for use on command line with B<-M> option as a way of testing
301 arbitrary scripts against an uninstalled version of a package.
302
303 =item use locale
304
305 Tells the compiler to enable (or disable) the use of POSIX locales for
306 built-in operations.
307
308 When C<use locale> is in effect, the current LC_CTYPE locale is used
309 for regular expressions and case mapping; LC_COLLATE for string
310 ordering; and LC_NUMERIC for numeric formating in printf and sprintf
311 (but B<not> in print).  LC_NUMERIC is always used in write, since
312 lexical scoping of formats is problematic at best.
313
314 Each C<use locale> or C<no locale> affects statements to the end of
315 the enclosing BLOCK or, if not inside a BLOCK, to the end of the
316 current file.  Locales can be switched and queried with
317 POSIX::setlocale().
318
319 See L<perllocale> for more information.
320
321 =item use ops
322
323 Restricts unsafe operations when compiling.
324
325 =back
326
327 =head1 Modules
328
329 =head2 Module Information Summary
330
331 Brand new modules:
332
333     IO.pm                Top-level interface to IO::* classes
334     IO/File.pm           IO::File extension Perl module
335     IO/Handle.pm         IO::Handle extension Perl module
336     IO/Pipe.pm           IO::Pipe extension Perl module
337     IO/Seekable.pm       IO::Seekable extension Perl module
338     IO/Select.pm         IO::Select extension Perl module
339     IO/Socket.pm         IO::Socket extension Perl module
340
341     Opcode.pm            Disable named opcodes when compiling Perl code
342
343     ExtUtils/Embed.pm    Utilities for embedding Perl in C programs
344     ExtUtils/testlib.pm  Fixes up @INC to use just-built extension
345
346     Fatal.pm             Make do-or-die equivalents of functions
347     FindBin.pm           Find path of currently executing program
348
349     Class/Template.pm    Structure/member template builder
350     File/stat.pm         Object-oriented wrapper around CORE::stat
351     Net/hostent.pm       Object-oriented wrapper around CORE::gethost*
352     Net/netent.pm        Object-oriented wrapper around CORE::getnet*
353     Net/protoent.pm      Object-oriented wrapper around CORE::getproto*
354     Net/servent.pm       Object-oriented wrapper around CORE::getserv*
355     Time/gmtime.pm       Object-oriented wrapper around CORE::gmtime
356     Time/localtime.pm    Object-oriented wrapper around CORE::localtime
357     Time/tm.pm           Perl implementation of "struct tm" for {gm,local}time
358     User/grent.pm        Object-oriented wrapper around CORE::getgr*
359     User/pwent.pm        Object-oriented wrapper around CORE::getpw*
360
361     UNIVERSAL.pm         Base class for *ALL* classes
362
363 =head2 IO
364
365 The IO module provides a simple mechanism to load all of the IO modules at one
366 go.  Currently this includes:
367
368      IO::Handle
369      IO::Seekable
370      IO::File
371      IO::Pipe
372      IO::Socket
373
374 For more information on any of these modules, please see its
375 respective documentation.
376
377 =head2 Math::Complex
378
379 The Math::Complex module has been totally rewritten, and now supports
380 more operations.  These are overloaded:
381
382      + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
383
384 And these functions are now exported:
385
386     pi i Re Im arg
387     log10 logn cbrt root
388     tan cotan asin acos atan acotan
389     sinh cosh tanh cotanh asinh acosh atanh acotanh
390     cplx cplxe
391
392 =head2 Overridden Built-ins
393
394 Many of the Perl built-ins returning lists now have
395 object-oriented overrides.  These are:
396
397     File::stat
398     Net::hostent
399     Net::netent
400     Net::protoent
401     Net::servent
402     Time::gmtime
403     Time::localtime
404     User::grent
405     User::pwent
406
407 For example, you can now say
408
409     use File::stat;
410     use User::pwent;
411     $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
412
413 =head1 Efficiency Enhancements
414
415 All hash keys with the same string are only allocated once, so
416 even if you have 100 copies of the same hash, the immutable keys
417 never have to be re-allocated.
418
419 Functions that do nothing but return a fixed value are now inlined.
420
421 =head1 Documentation Changes
422
423 Many of the base and library pods were updated.  These
424 new pods are included in section 1:
425
426 =over 4
427
428 =item L<perli18n>
429
430 Internationalization.
431
432 =item L<perlapio>
433
434 Perl internal IO abstraction interface.
435
436 =item L<perltoot>
437
438 Tutorial on Perl OO programming.
439
440 =item L<perldebug>
441
442 Although not new, this has been massively updated.
443
444 =item L<perlsec>
445
446 Although not new, this has been massively updated.
447
448 =back
449
450 =head1 New Diagnostics
451
452 Several new conditions will trigger warnings that were
453 silent before.  Some only affect certain platforms.
454 The following new warnings and errors
455 outline these:
456
457 =over 4
458
459 =item "my" variable %s masks earlier declaration in same scope
460
461 (S) A lexical variable has been redeclared in the same scope, effectively
462 eliminating all access to the previous instance.  This is almost always
463 a typographical error.  Note that the earlier variable will still exist
464 until the end of the scope or until all closure referents to it are
465 destroyed.
466
467 =item Allocation too large: %lx
468
469 (X) You can't allocate more than 64K on an MSDOS machine.
470
471 =item Allocation too large
472
473 (F) You can't allocate more than 2^31+"small amount" bytes.
474
475 =item Attempt to free non-existent shared string
476
477 (P) Perl maintains a reference counted internal table of strings to
478 optimize the storage and access of hash keys and other strings.  This
479 indicates someone tried to decrement the reference count of a string
480 that can no longer be found in the table.
481
482 =item Attempt to use reference as lvalue in substr
483
484 (W) You supplied a reference as the first argument to substr() used
485 as an lvalue, which is pretty strange.  Perhaps you forgot to
486 dereference it first.  See L<perlfunc/substr>.
487
488 =item Unsupported function fork
489
490 (F) Your version of executable does not support forking.
491
492 Note that under some systems, like OS/2, there may be different flavors of
493 Perl executables, some of which may support fork, some not. Try changing
494 the name you call Perl by to C<perl_>, C<perl__>, and so on.
495
496 =item Ill-formed logical name |%s| in prime_env_iter
497
498 (W) A warning peculiar to VMS.  A logical name was encountered when preparing
499 to iterate over %ENV which violates the syntactic rules governing logical
500 names.  Since it cannot be translated normally, it is skipped, and will not
501 appear in %ENV.  This may be a benign occurrence, as some software packages
502 might directly modify logical name tables and introduce non-standard names,
503 or it may indicate that a logical name table has been corrupted.
504
505 =item Integer overflow in hex number
506
507 (S) The literal hex number you have specified is too big for your
508 architecture. On a 32-bit architecture the largest hex literal is
509 0xFFFFFFFF.
510
511 =item Integer overflow in octal number
512
513 (S) The literal octal number you have specified is too big for your
514 architecture. On a 32-bit architecture the largest octal literal is
515 037777777777.
516
517 =item Null picture in formline
518
519 (F) The first argument to formline must be a valid format picture
520 specification.  It was found to be empty, which probably means you
521 supplied it an uninitialized value.  See L<perlform>.
522
523 =item Offset outside string
524
525 (F) You tried to do a read/write/send/recv operation with an offset
526 pointing outside the buffer.  This is difficult to imagine.
527 The sole exception to this is that C<sysread()>ing past the buffer
528 will extend the buffer and zero pad the new area.
529
530 =item Out of memory!
531
532 (X|F) The malloc() function returned 0, indicating there was insufficient
533 remaining memory (or virtual memory) to satisfy the request.
534
535 The request was judged to be small, so the possibility to trap it
536 depends on the way Perl was compiled.  By default it is not trappable.
537 However, if compiled for this, Perl may use the contents of C<$^M> as
538 an emergency pool after die()ing with this message.  In this case the
539 error is trappable I<once>.
540
541 =item Out of memory during request for %s
542
543 (F) The malloc() function returned 0, indicating there was insufficient
544 remaining memory (or virtual memory) to satisfy the request. However,
545 the request was judged large enough (compile-time default is 64K), so
546 a possibility to shut down by trapping this error is granted.
547
548 =item Possible attempt to put comments in qw() list
549
550 (W) You probably wrote something like this:
551
552     qw( a # a comment
553         b # another comment
554       ) ;
555
556 when you should have written this:
557
558     qw( a
559         b
560       ) ;
561
562 =item Possible attempt to separate words with commas
563
564 (W) You probably wrote something like this:
565
566     qw( a, b, c );
567
568 when you should have written this:
569
570     qw( a b c );
571
572 =item untie attempted while %d inner references still exist
573
574 (W) A copy of the object returned from C<tie> (or C<tied>) was still
575 valid when C<untie> was called.
576
577 =item Got an error from DosAllocMem:
578
579 (P) An error peculiar to OS/2. Most probably you use an obsolete version
580 of Perl, and should not happen anyway.
581
582 =item Malformed PERLLIB_PREFIX
583
584 (F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
585
586     prefix1;prefix2
587
588 or
589
590     prefix1 prefix2
591
592 with non-empty prefix1 and prefix2. If C<prefix1> is indeed a prefix of
593 a builtin library search path, prefix2 is substituted. The error may appear
594 if components are not found, or are too long. See L<perlos2/"PERLLIB_PREFIX">.
595
596 =item PERL_SH_DIR too long
597
598 (F) An error peculiar to OS/2. PERL_SH_DIR is the directory to find the
599 C<sh>-shell in. See L<perlos2/"PERL_SH_DIR">.
600
601 =item Process terminated by SIG%s
602
603 (W) This is a standard message issued by OS/2 applications, while *nix
604 applications die in silence. It is considered a feature of the OS/2
605 port. One can easily disable this by appropriate sighandlers, see
606 L<perlipc/"Signals">.  See L<perlos2/"Process terminated by SIGTERM/SIGINT">.
607
608 =back
609
610 =head1 BUGS
611
612 If you find what you think is a bug, you might check the headers
613 of recently posted articles 
614 in the comp.lang.perl.misc newsgroup.  There may also be
615 information at http://www.perl.com/perl/, the Perl Home Page.
616
617 If you believe you have an unreported bug, please run the B<perlbug>
618 program included with your release.  Make sure you trim your bug
619 down to a tiny but sufficient test case.  Your bug report, along
620 with the output of C<perl -V>, will be sent off to perlbug@perl.com
621 to be analysed by the Perl porting team.
622
623 =head1 SEE ALSO
624
625 The F<Changes> file for exhaustive details on what changed.
626
627 The F<INSTALL> file for how to build Perl.  This file has been
628 significantly updated for 5.004, so even veteran users should
629 look through it.
630
631 The F<README> file for general stuff.
632
633 The F<Copying> file for copyright information.
634
635 =head1 HISTORY
636
637 Constructed by Tom Christiansen, grabbing material with permission
638 from innumerable contributors, with kibitzing by more than a few Perl
639 porters.
640
641 Last update:
642 Wed Dec 18 16:18:27 EST 1996