Efficiency patchlet for pp_aassign()
[p5sagit/p5-mst-13.2.git] / pod / perldelta.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
44a8e56a 26might have symbol conflicts if you embed Perl in another application,
27just as in the 5.003 release.
5f05dabc 28
7cfe7857 29=head2 New Opcode Module and Revised Safe Module
30
31A new Opcode module supports the creation, manipulation and
32application of opcode masks. The revised Safe module has a new API
33and is implemented using the new Opcode module. Please read the new
34Opcode and Safe documentation.
35
5f05dabc 36=head2 Internal Change: FileHandle Deprecated
37
38Filehandles are now stored internally as type IO::Handle.
39Although C<use FileHandle> and C<*STDOUT{FILEHANDLE}>
40are still supported for backwards compatibility
41C<use IO::Handle> (or C<IO::Seekable> or C<IO::File>) and
42C<*STDOUT{IO}> are the way of the future.
43
28757baa 44=head2 Internal Change: PerlIO internal IO abstraction interface
5f05dabc 45
46It is now possible to build Perl with AT&T's sfio IO package
47instead of stdio. See L<perlapio> for more details, and
48the 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
56Extended error message under some platforms ($EXTENDED_OS_ERROR
57if you C<use English>).
58
59=item $^H
60
61The current set of syntax checks enabled by C<use strict>. See the
62documentation of C<strict> for more details. Not actually new, but
63newly documented.
64Because it is intended for internal use by Perl core components,
65there is no C<use English> long name for this variable.
66
67=item $^M
68
69By default, running out of memory it is not trappable. However, if
70compiled for this, Perl may use the contents of C<$^M> as an emergency
71pool after die()ing with this message. Suppose that your Perl were
72compiled with -DEMERGENCY_SBRK and used Perl's malloc. Then
73
74 $^M = 'a' x (1<<16);
75
76would allocate 64K buffer for use when in emergency.
77See the F<INSTALL> file for information on how to enable this option.
78As a disincentive to casual use of this advanced feature,
79there 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
89This now works. (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
90
91=item flock
92
93is now supported on more platforms, and prefers fcntl
94to lockf when emulating.
95
96=item keys as an lvalue
97
98As an lvalue, C<keys> allows you to increase the number of hash buckets
99allocated for the given associative array. This can gain you a measure
100of efficiency if you know the hash is going to get big. (This is
101similar to pre-extending an array by assigning a larger number to
102$#array.) If you say
103
104 keys %hash = 200;
105
106then C<%hash> will have at least 200 buckets allocated for it. These
107buckets 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.
109You can't shrink the number of buckets allocated for the hash using
110C<keys> in this way (but you needn't worry about doing this by accident,
111as trying has no effect).
112
113=item my() in Control Structures
114
115You can now use my() (with or without the parentheses) in the control
116expressions 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
133Also, you can declare a foreach loop control variable as lexical by
134preceding 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
141the loop, but not beyond it.
142
143Note that you still cannot use my() on global punctuation variables
144such as $_ and the like.
145
146=item unpack() and pack()
147
148A new format 'w' represents a BER compressed integer (as defined in
149ASN.1). Its format is a sequence of one or more bytes, each of which
150provides seven bits of the total value, with the most significant
151first. Bit eight of each byte is set, except for the last byte, in
152which bit eight is clear.
153
154=item use VERSION
155
156If the first argument to C<use> is a number, it is treated as a version
157number instead of a module name. If the version of the Perl interpreter
158is less than VERSION, then an error message is printed and Perl exits
159immediately. This is often useful if you need to check the current
160Perl version before C<use>ing library modules which have changed in
161incompatible ways from older versions of Perl. (We try not to do
162this more than we have to.)
163
164=item use Module VERSION LIST
165
166If the VERSION argument is present between Module and LIST, then the
71be2cbc 167C<use> will call the VERSION method in class Module with the given
168version as an argument. The default VERSION method, inherited from
169the Universal class, croaks if the given version is larger than the
170value of the variable $Module::VERSION. (Note that there is not a
171comma after VERSION!)
5f05dabc 172
7cfe7857 173This version-checking mechanism is similar to the one currently used
174in the Exporter module, but it is faster and can be used with modules
175that don't use the Exporter. It is the recommended method for new
176code.
177
5f05dabc 178=item prototype(FUNCTION)
179
180Returns the prototype of a function as a string (or C<undef> if the
181function has no prototype). FUNCTION is a reference to or the name of the
182function whose prototype you want to retrieve.
183(Not actually new; just never documented before.)
184
185=item $_ as Default
186
187Functions documented in the Camel to default to $_ now in
188fact do, and all those that do are so documented in L<perlfunc>.
189
44a8e56a 190=head2 C<m//g> does not trigger a pos() reset on failure
191
192The C<m//g> match iteration construct used to reset the iteration
193when it failed to match (so that the next C<m//g> match would start at
194the beginning of the string). You now have to explicitly do a
195C<pos $str = 0;> to reset the "last match" position, or modify the
196string in some way. This change makes it practical to chain C<m//g>
197matches together in conjunction with ordinary matches using the C<\G>
198zero-width assertion. See L<perlop> and L<perlre>.
199
5f05dabc 200=back
201
202=head2 New Built-in Methods
203
204The C<UNIVERSAL> package automatically contains the following methods that
205are inherited by all other classes:
206
207=over 4
208
209=item isa(CLASS)
210
211C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
212
213C<isa> is also exportable and can be called as a sub with two arguments. This
214allows 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
224C<can> checks to see if its object has a method called C<METHOD>,
225if it does then a reference to the sub is returned; if it does not then
226I<undef> is returned.
227
228=item VERSION( [NEED] )
229
71be2cbc 230C<VERSION> returns the version number of the class (package). If the
231NEED argument is given then it will check that the current version (as
232defined by the $VERSION variable in the given package) not less than
233NEED; it will die if this is not the case. This method is normally
234called as a class method. This method is called automatically by the
235C<VERSION> form of C<use>.
5f05dabc 236
237 use A 1.2 qw(some imported subs);
71be2cbc 238 # implies:
239 A->VERSION(1.2);
5f05dabc 240
241=item class()
242
243C<class> returns the class name of its object.
244
245=item is_instance()
246
247C<is_instance> returns true if its object is an instance of some
248class, 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
260B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
261C<isa> uses a very similar method and cache-ing strategy. This may cause
262strange effects if the Perl code dynamically changes @ISA in any package.
263
264You may add other methods to the UNIVERSAL class via Perl or XS code.
265You do not need to C<use UNIVERSAL> in order to make these methods
266available to your program. This is necessary only if you wish to
267have 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
275This is the constructor for the class. That means it is expected to
276return an object of some sort. The reference can be used to
277hold some internal information.
278
279 sub TIEHANDLE { print "<shout>\n"; my $i; bless \$i, shift }
280
281=item PRINT this, LIST
282
283This method will be triggered every time the tied handle is printed to.
284Beyond its self reference it also expects the list that was passed to
285the print function.
286
287 sub PRINT { $r = shift; $$r++; print join($,,map(uc($_),@_)),$\ }
288
289=item READLINE this
290
291This method will be called when the handle is read from. The method
292should 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
298As with the other types of ties, this method will be called when the
299tied handle is about to be destroyed. This is useful for debugging and
300possibly for cleaning up.
301
302 sub DESTROY { print "</shout>\n" }
303
304=back
305
306=head1 Pragmata
307
308Three new pragmatic modules exist:
309
310=over
311
312=item use blib
313
314Looks for MakeMaker-like I<'blib'> directory structure starting in
315I<dir> (or current directory) and working back up to five levels of
316parent directories.
317
318Intended for use on command line with B<-M> option as a way of testing
319arbitrary scripts against an uninstalled version of a package.
320
321=item use locale
322
323Tells the compiler to enable (or disable) the use of POSIX locales for
324built-in operations.
325
326When C<use locale> is in effect, the current LC_CTYPE locale is used
327for regular expressions and case mapping; LC_COLLATE for string
328ordering; and LC_NUMERIC for numeric formating in printf and sprintf
329(but B<not> in print). LC_NUMERIC is always used in write, since
330lexical scoping of formats is problematic at best.
331
332Each C<use locale> or C<no locale> affects statements to the end of
333the enclosing BLOCK or, if not inside a BLOCK, to the end of the
334current file. Locales can be switched and queried with
335POSIX::setlocale().
336
337See L<perllocale> for more information.
338
339=item use ops
340
7cfe7857 341Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
5f05dabc 342
343=back
344
345=head1 Modules
346
347=head2 Module Information Summary
348
349Brand 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
7a4c00b4 379 lib/Tie/RefHash.pm Base class for tied hashes with references as keys
380
5f05dabc 381 UNIVERSAL.pm Base class for *ALL* classes
382
383=head2 IO
384
385The IO module provides a simple mechanism to load all of the IO modules at one
386go. Currently this includes:
387
388 IO::Handle
389 IO::Seekable
390 IO::File
391 IO::Pipe
392 IO::Socket
393
394For more information on any of these modules, please see its
395respective documentation.
396
397=head2 Math::Complex
398
399The Math::Complex module has been totally rewritten, and now supports
400more operations. These are overloaded:
401
402 + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
403
404And 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
414Many of the Perl built-ins returning lists now have
415object-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
427For 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
435All hash keys with the same string are only allocated once, so
436even if you have 100 copies of the same hash, the immutable keys
437never have to be re-allocated.
438
7cfe7857 439Functions that have an empty prototype and that do nothing but return
440a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
5f05dabc 441
442=head1 Documentation Changes
443
444Many of the base and library pods were updated. These
445new pods are included in section 1:
446
447=over 4
448
71be2cbc 449=item L<perlnews>
5f05dabc 450
71be2cbc 451This document.
5f05dabc 452
71be2cbc 453=item L<perllocale>
5f05dabc 454
71be2cbc 455Locale support (internationalization and localization).
5f05dabc 456
457=item L<perltoot>
458
459Tutorial on Perl OO programming.
460
71be2cbc 461=item L<perlapio>
462
463Perl internal IO abstraction interface.
464
5f05dabc 465=item L<perldebug>
466
467Although not new, this has been massively updated.
468
469=item L<perlsec>
470
471Although not new, this has been massively updated.
472
473=back
474
475=head1 New Diagnostics
476
477Several new conditions will trigger warnings that were
478silent before. Some only affect certain platforms.
479The following new warnings and errors
480outline 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
487eliminating all access to the previous instance. This is almost always
488a typographical error. Note that the earlier variable will still exist
489until the end of the scope or until all closure referents to it are
490destroyed.
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
503optimize the storage and access of hash keys and other strings. This
504indicates someone tried to decrement the reference count of a string
505that 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
510as an lvalue, which is pretty strange. Perhaps you forgot to
511dereference it first. See L<perlfunc/substr>.
512
513=item Unsupported function fork
514
515(F) Your version of executable does not support forking.
516
517Note that under some systems, like OS/2, there may be different flavors of
518Perl executables, some of which may support fork, some not. Try changing
519the 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
524to iterate over %ENV which violates the syntactic rules governing logical
525names. Since it cannot be translated normally, it is skipped, and will not
526appear in %ENV. This may be a benign occurrence, as some software packages
527might directly modify logical name tables and introduce non-standard names,
528or 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
533architecture. On a 32-bit architecture the largest hex literal is
5340xFFFFFFFF.
535
536=item Integer overflow in octal number
537
538(S) The literal octal number you have specified is too big for your
539architecture. On a 32-bit architecture the largest octal literal is
540037777777777.
541
542=item Null picture in formline
543
544(F) The first argument to formline must be a valid format picture
545specification. It was found to be empty, which probably means you
546supplied 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
551pointing outside the buffer. This is difficult to imagine.
552The sole exception to this is that C<sysread()>ing past the buffer
553will 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
558remaining memory (or virtual memory) to satisfy the request.
559
560The request was judged to be small, so the possibility to trap it
561depends on the way Perl was compiled. By default it is not trappable.
562However, if compiled for this, Perl may use the contents of C<$^M> as
563an emergency pool after die()ing with this message. In this case the
564error 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
569remaining memory (or virtual memory) to satisfy the request. However,
570the request was judged large enough (compile-time default is 64K), so
571a 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
581when 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
593when 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
600valid 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
605of 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
613or
614
615 prefix1 prefix2
616
617with non-empty prefix1 and prefix2. If C<prefix1> is indeed a prefix of
618a builtin library search path, prefix2 is substituted. The error may appear
619if 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
624C<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
629applications die in silence. It is considered a feature of the OS/2
630port. One can easily disable this by appropriate sighandlers, see
631L<perlipc/"Signals">. See L<perlos2/"Process terminated by SIGTERM/SIGINT">.
632
633=back
634
635=head1 BUGS
636
637If you find what you think is a bug, you might check the headers
638of recently posted articles
639in the comp.lang.perl.misc newsgroup. There may also be
640information at http://www.perl.com/perl/, the Perl Home Page.
641
642If you believe you have an unreported bug, please run the B<perlbug>
643program included with your release. Make sure you trim your bug
644down to a tiny but sufficient test case. Your bug report, along
645with the output of C<perl -V>, will be sent off to perlbug@perl.com
646to be analysed by the Perl porting team.
647
648=head1 SEE ALSO
649
650The F<Changes> file for exhaustive details on what changed.
651
652The F<INSTALL> file for how to build Perl. This file has been
653significantly updated for 5.004, so even veteran users should
654look through it.
655
656The F<README> file for general stuff.
657
658The F<Copying> file for copyright information.
659
660=head1 HISTORY
661
662Constructed by Tom Christiansen, grabbing material with permission
663from innumerable contributors, with kibitzing by more than a few Perl
664porters.
665
44a8e56a 666Last update: Tue Jan 14 14:03:02 EST 1997