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