DB_File documentation fix
[p5sagit/p5-mst-13.2.git] / pod / perldelta.pod
CommitLineData
5f05dabc 1=head1 NAME
2
774d564b 3perldelta - what's new for perl5.004
5f05dabc 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,
774d564b 27just as in the 5.003 release. By default, binary compatibility
28is preserved at the expense of symbol table pollution.
5f05dabc 29
68dc0745 30=head2 No Autovivification of Subroutine Parameters
7cfe7857 31
2ae324a7 32In Perl versions 5.002 and 5.003, array and hash elements used as
33subroutine parameters were "autovivified"; that is, they were brought
34into existence if they did not already exist. For example, calling
35C<func($h{foo})> would create C<$h{foo}> if it did not already exist,
36causing C<exists $h{foo}> to become true and C<keys %h> to return
37C<('foo')>.
38
39Perl 5.004 returns to the pre-5.002 behavior of I<not> autovivifying
40array and hash elements used as subroutine parameters.
7cfe7857 41
aa689395 42=head2 Fixed Parsing of $$<digit>, &$<digit>, etc.
43
44A bug in previous versions of Perl 5.0 prevented proper parsing of
45numeric special variables as symbolic references. That bug has been
46fixed. As a result, the string "$$0" is no longer equivalent to
47C<$$."0">, but rather to C<${$0}>. To get the old behavior, change
48"$$" followed by a digit to "${$}".
49
68dc0745 50=head2 No Resetting of $. on Implicit Close
51
52The documentation for Perl 5.0 has always stated that C<$.> is I<not>
53reset when an already-open file handle is re-opened with no intervening
54call to C<close>. Due to a bug, perl versions 5.000 through 5.0003
55I<did> reset C<$.> under that circumstance; Perl 5.004 does not.
56
9607fc9c 57=head2 Changes to Tainting Checks
5f05dabc 58
9607fc9c 59A bug in previous versions may have failed to detect some insecure
60conditions when taint checks are turned on. (Taint checks are used
61in setuid or setgid scripts, or when explicitly turned on with the
62C<-T> invocation option.) Although it's unlikely, this may cause a
63previously-working script to now fail -- which should be construed
64as a blessing, since that indicates a potentially-serious security
65hole was just plugged.
66
2ae324a7 67=head2 New Opcode Module and Revised Safe Module
68
69A new Opcode module supports the creation, manipulation and
70application of opcode masks. The revised Safe module has a new API
71and is implemented using the new Opcode module. Please read the new
72Opcode and Safe documentation.
73
68dc0745 74=head2 Embedding Improvements
75
76In older versions of Perl it was not possible to create more than one
77Perl interpreter instance inside a single process without leaking like a
78sieve and/or crashing. The bugs that caused this behavior have all been
79fixed. However, you still must take care when embedding Perl in a C
80program. See the updated perlembed manpage for tips on how to manage
81your interpreters.
82
9607fc9c 83=head2 Internal Change: FileHandle Class Based on IO::* Classes
84
85File handles are now stored internally as type IO::Handle. The
86FileHandle module is still supported for backwards compatibility, but
87it is now merely a front end to the IO::* modules -- specifically,
88IO::Handle, IO::Seekable, and IO::File. We suggest, but do not
89require, that you use the IO::* modules in new code.
90
91In harmony with this change, C<*GLOB{FILEHANDLE}> is now a
92backward-compatible synonym for C<*STDOUT{IO}>.
5f05dabc 93
28757baa 94=head2 Internal Change: PerlIO internal IO abstraction interface
5f05dabc 95
96It is now possible to build Perl with AT&T's sfio IO package
97instead of stdio. See L<perlapio> for more details, and
98the F<INSTALL> file for how to use it.
99
100=head2 New and Changed Built-in Variables
101
102=over
103
104=item $^E
105
f86702cc 106Extended error message on some platforms. (Also known as
107$EXTENDED_OS_ERROR if you C<use English>).
5f05dabc 108
109=item $^H
110
111The current set of syntax checks enabled by C<use strict>. See the
112documentation of C<strict> for more details. Not actually new, but
113newly documented.
114Because it is intended for internal use by Perl core components,
115there is no C<use English> long name for this variable.
116
117=item $^M
118
119By default, running out of memory it is not trappable. However, if
120compiled for this, Perl may use the contents of C<$^M> as an emergency
121pool after die()ing with this message. Suppose that your Perl were
122compiled with -DEMERGENCY_SBRK and used Perl's malloc. Then
123
124 $^M = 'a' x (1<<16);
125
774d564b 126would allocate a 64K buffer for use when in emergency.
5f05dabc 127See the F<INSTALL> file for information on how to enable this option.
128As a disincentive to casual use of this advanced feature,
129there is no C<use English> long name for this variable.
130
131=back
132
133=head2 New and Changed Built-in Functions
134
135=over
136
137=item delete on slices
138
139This now works. (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
140
141=item flock
142
68dc0745 143is now supported on more platforms, prefers fcntl to lockf when
144emulating, and always flushes before (un)locking.
5f05dabc 145
046ff0ed 146=item printf and sprintf
147
148now support "%i" as a synonym for "%d", and the "h" modifier.
149So "%hi" means "short integer in decimal", and "%ho" means
150"unsigned short integer as octal".
151
5f05dabc 152=item keys as an lvalue
153
154As an lvalue, C<keys> allows you to increase the number of hash buckets
aa689395 155allocated for the given hash. This can gain you a measure of efficiency if
156you know the hash is going to get big. (This is similar to pre-extending
157an array by assigning a larger number to $#array.) If you say
5f05dabc 158
159 keys %hash = 200;
160
161then C<%hash> will have at least 200 buckets allocated for it. These
162buckets will be retained even if you do C<%hash = ()>; use C<undef
163%hash> if you want to free the storage while C<%hash> is still in scope.
164You can't shrink the number of buckets allocated for the hash using
165C<keys> in this way (but you needn't worry about doing this by accident,
166as trying has no effect).
167
168=item my() in Control Structures
169
170You can now use my() (with or without the parentheses) in the control
171expressions of control structures such as:
172
aa689395 173 while (defined(my $line = <>)) {
5f05dabc 174 $line = lc $line;
175 } continue {
176 print $line;
177 }
178
774d564b 179 if ((my $answer = <STDIN>) =~ /^y(es)?$/i) {
5f05dabc 180 user_agrees();
774d564b 181 } elsif ($answer =~ /^n(o)?$/i) {
5f05dabc 182 user_disagrees();
183 } else {
184 chomp $answer;
774d564b 185 die "`$answer' is neither `yes' nor `no'";
5f05dabc 186 }
187
188Also, you can declare a foreach loop control variable as lexical by
189preceding it with the word "my". For example, in:
190
191 foreach my $i (1, 2, 3) {
192 some_function();
193 }
194
195$i is a lexical variable, and the scope of $i extends to the end of
196the loop, but not beyond it.
197
198Note that you still cannot use my() on global punctuation variables
199such as $_ and the like.
200
201=item unpack() and pack()
202
203A new format 'w' represents a BER compressed integer (as defined in
204ASN.1). Its format is a sequence of one or more bytes, each of which
205provides seven bits of the total value, with the most significant
206first. Bit eight of each byte is set, except for the last byte, in
207which bit eight is clear.
208
209=item use VERSION
210
211If the first argument to C<use> is a number, it is treated as a version
212number instead of a module name. If the version of the Perl interpreter
213is less than VERSION, then an error message is printed and Perl exits
774d564b 214immediately. Because C<use> occurs at compile time, this check happens
215immediately during the compilation process, unlike C<require VERSION>,
216which waits until run-time for the check. This is often useful if you
217need to check the current Perl version before C<use>ing library modules
218which have changed in incompatible ways from older versions of Perl.
219(We try not to do this more than we have to.)
5f05dabc 220
221=item use Module VERSION LIST
222
223If the VERSION argument is present between Module and LIST, then the
71be2cbc 224C<use> will call the VERSION method in class Module with the given
225version as an argument. The default VERSION method, inherited from
226the Universal class, croaks if the given version is larger than the
227value of the variable $Module::VERSION. (Note that there is not a
228comma after VERSION!)
5f05dabc 229
7cfe7857 230This version-checking mechanism is similar to the one currently used
231in the Exporter module, but it is faster and can be used with modules
232that don't use the Exporter. It is the recommended method for new
233code.
234
5f05dabc 235=item prototype(FUNCTION)
236
237Returns the prototype of a function as a string (or C<undef> if the
238function has no prototype). FUNCTION is a reference to or the name of the
239function whose prototype you want to retrieve.
240(Not actually new; just never documented before.)
241
9607fc9c 242=item srand
243
244The default seed for C<srand>, which used to be C<time>, has been changed.
245Now it's a heady mix of difficult-to-predict system-dependent values,
246which should be sufficient for most everyday purposes.
247
248Previous to version 5.004, calling C<rand> without first calling C<srand>
249would yield the same sequence of random numbers on most or all machines.
250Now, when perl sees that you're calling C<rand> and haven't yet called
251C<srand>, it calls C<srand> with the default seed. You should still call
252C<srand> manually if your code might ever be run on a pre-5.004 system,
2ae324a7 253of course, or if you want a seed other than the default.
9607fc9c 254
5f05dabc 255=item $_ as Default
256
257Functions documented in the Camel to default to $_ now in
258fact do, and all those that do are so documented in L<perlfunc>.
259
774d564b 260=item C<m//g> does not trigger a pos() reset on failure
44a8e56a 261
262The C<m//g> match iteration construct used to reset the iteration
263when it failed to match (so that the next C<m//g> match would start at
264the beginning of the string). You now have to explicitly do a
265C<pos $str = 0;> to reset the "last match" position, or modify the
266string in some way. This change makes it practical to chain C<m//g>
267matches together in conjunction with ordinary matches using the C<\G>
268zero-width assertion. See L<perlop> and L<perlre>.
269
774d564b 270=item nested C<sub{}> closures work now
271
2ae324a7 272Prior to the 5.004 release, nested anonymous functions didn't work
273right. They do now.
774d564b 274
275=item formats work right on changing lexicals
276
277Just like anonymous functions that contain lexical variables
278that change (like a lexical index variable for a C<foreach> loop),
279formats now work properly. For example, this silently failed
280before, and is fine now:
281
282 my $i;
283 foreach $i ( 1 .. 10 ) {
284 format =
285 my i is @#
286 $i
287 .
288 write;
2ae324a7 289 }
774d564b 290
5f05dabc 291=back
292
293=head2 New Built-in Methods
294
295The C<UNIVERSAL> package automatically contains the following methods that
296are inherited by all other classes:
297
0a753a76 298=over
5f05dabc 299
300=item isa(CLASS)
301
68dc0745 302C<isa> returns I<true> if its object is blessed into a subclass of C<CLASS>
5f05dabc 303
304C<isa> is also exportable and can be called as a sub with two arguments. This
305allows the ability to check what a reference points to. Example:
306
307 use UNIVERSAL qw(isa);
308
309 if(isa($ref, 'ARRAY')) {
310 ...
311 }
312
313=item can(METHOD)
314
315C<can> checks to see if its object has a method called C<METHOD>,
316if it does then a reference to the sub is returned; if it does not then
317I<undef> is returned.
318
319=item VERSION( [NEED] )
320
71be2cbc 321C<VERSION> returns the version number of the class (package). If the
322NEED argument is given then it will check that the current version (as
323defined by the $VERSION variable in the given package) not less than
324NEED; it will die if this is not the case. This method is normally
325called as a class method. This method is called automatically by the
326C<VERSION> form of C<use>.
5f05dabc 327
328 use A 1.2 qw(some imported subs);
71be2cbc 329 # implies:
330 A->VERSION(1.2);
5f05dabc 331
5f05dabc 332=back
333
334B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
774d564b 335C<isa> uses a very similar method and caching strategy. This may cause
5f05dabc 336strange effects if the Perl code dynamically changes @ISA in any package.
337
338You may add other methods to the UNIVERSAL class via Perl or XS code.
339You do not need to C<use UNIVERSAL> in order to make these methods
340available to your program. This is necessary only if you wish to
341have C<isa> available as a plain subroutine in the current package.
342
343=head2 TIEHANDLE Now Supported
344
774d564b 345See L<perltie> for other kinds of tie()s.
346
5f05dabc 347=over
348
349=item TIEHANDLE classname, LIST
350
351This is the constructor for the class. That means it is expected to
352return an object of some sort. The reference can be used to
353hold some internal information.
354
2ae324a7 355 sub TIEHANDLE {
356 print "<shout>\n";
357 my $i;
774d564b 358 return bless \$i, shift;
359 }
5f05dabc 360
361=item PRINT this, LIST
362
363This method will be triggered every time the tied handle is printed to.
364Beyond its self reference it also expects the list that was passed to
365the print function.
366
2ae324a7 367 sub PRINT {
368 $r = shift;
369 $$r++;
774d564b 370 return print join( $, => map {uc} @_), $\;
371 }
5f05dabc 372
2ae324a7 373=item READ this LIST
374
375This method will be called when the handle is read from via the C<read>
376or C<sysread> functions.
377
378 sub READ {
379 $r = shift;
380 my($buf,$len,$offset) = @_;
381 print "READ called, \$buf=$buf, \$len=$len, \$offset=$offset";
382 }
383
5f05dabc 384=item READLINE this
385
386This method will be called when the handle is read from. The method
387should return undef when there is no more data.
388
2ae324a7 389 sub READLINE {
390 $r = shift;
391 return "PRINT called $$r times\n"
774d564b 392 }
5f05dabc 393
2ae324a7 394=item GETC this
395
396This method will be called when the C<getc> function is called.
397
398 sub GETC { print "Don't GETC, Get Perl"; return "a"; }
399
5f05dabc 400=item DESTROY this
401
402As with the other types of ties, this method will be called when the
403tied handle is about to be destroyed. This is useful for debugging and
404possibly for cleaning up.
405
2ae324a7 406 sub DESTROY {
774d564b 407 print "</shout>\n";
408 }
5f05dabc 409
410=back
411
aa689395 412=head2 Malloc Enhancements
413
2ae324a7 414Four new compilation flags are recognized by malloc.c. (They have no
415effect if perl is compiled with system malloc().)
416
417=over
418
419=item -DDEBUGGING_MSTATS
420
421If perl is compiled with C<DEBUGGING_MSTATS> defined, you can print
422memory statistics at runtime by running Perl thusly:
aa689395 423
424 env PERL_DEBUG_MSTATS=2 perl your_script_here
425
426The value of 2 means to print statistics after compilation and on
427exit; with a value of 1, the statistics ares printed only on exit.
428(If you want the statistics at an arbitrary time, you'll need to
429install the optional module Devel::Peek.)
430
aa689395 431=item -DEMERGENCY_SBRK
432
433If this macro is defined, running out of memory need not be a fatal
434error: a memory pool can allocated by assigning to the special
435variable C<$^M>. See L<"$^M">.
774d564b 436
aa689395 437=item -DPACK_MALLOC
438
439Perl memory allocation is by bucket with sizes close to powers of two.
440Because of these malloc overhead may be big, especially for data of
441size exactly a power of two. If C<PACK_MALLOC> is defined, perl uses
442a slightly different algorithm for small allocations (up to 64 bytes
443long), which makes it possible to have overhead down to 1 byte for
444allocations which are powers of two (and appear quite often).
445
446Expected memory savings (with 8-byte alignment in C<alignbytes>) is
447about 20% for typical Perl usage. Expected slowdown due to additional
448malloc overhead is in fractions of a percent (hard to measure, because
449of the effect of saved memory on speed).
450
451=item -DTWO_POT_OPTIMIZE
452
453Similarly to C<PACK_MALLOC>, this macro improves allocations of data
454with size close to a power of two; but this works for big allocations
455(starting with 16K by default). Such allocations are typical for big
456hashes and special-purpose scripts, especially image processing.
457
458On recent systems, the fact that perl requires 2M from system for 1M
459allocation will not affect speed of execution, since the tail of such
460a chunk is not going to be touched (and thus will not require real
461memory). However, it may result in a premature out-of-memory error.
462So if you will be manipulating very large blocks with sizes close to
463powers of two, it would be wise to define this macro.
464
465Expected saving of memory is 0-100% (100% in applications which
466require most memory in such 2**n chunks); expected slowdown is
467negligible.
468
469=back
470
471=head2 Miscellaneous Efficiency Enhancements
774d564b 472
473Functions that have an empty prototype and that do nothing but return
474a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
475
aa689395 476Each unique hash key is only allocated once, no matter how many hashes
477have an entry with that key. So even if you have 100 copies of the
68dc0745 478same hash, the hash keys never have to be reallocated.
aa689395 479
5f05dabc 480=head1 Pragmata
481
ff0cee69 482Four new pragmatic modules exist:
5f05dabc 483
484=over
485
486=item use blib
487
774d564b 488=item use blib 'dir'
489
5f05dabc 490Looks for MakeMaker-like I<'blib'> directory structure starting in
491I<dir> (or current directory) and working back up to five levels of
492parent directories.
493
494Intended for use on command line with B<-M> option as a way of testing
495arbitrary scripts against an uninstalled version of a package.
496
497=item use locale
498
499Tells the compiler to enable (or disable) the use of POSIX locales for
500built-in operations.
501
502When C<use locale> is in effect, the current LC_CTYPE locale is used
503for regular expressions and case mapping; LC_COLLATE for string
504ordering; and LC_NUMERIC for numeric formating in printf and sprintf
505(but B<not> in print). LC_NUMERIC is always used in write, since
506lexical scoping of formats is problematic at best.
507
508Each C<use locale> or C<no locale> affects statements to the end of
509the enclosing BLOCK or, if not inside a BLOCK, to the end of the
510current file. Locales can be switched and queried with
511POSIX::setlocale().
512
513See L<perllocale> for more information.
514
515=item use ops
516
7cfe7857 517Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
5f05dabc 518
ff0cee69 519=item use vmsish
520
521Enable VMS-specific language features. Currently, there are three
aa689395 522VMS-specific features available: 'status', which makes C<$?> and
ff0cee69 523C<system> return genuine VMS status values instead of emulating POSIX;
524'exit', which makes C<exit> take a genuine VMS status value instead of
525assuming that C<exit 1> is an error; and 'time', which makes all times
526relative to the local time zone, in the VMS tradition.
527
5f05dabc 528=back
529
530=head1 Modules
531
f86702cc 532=head2 Installation Directories
533
534The I<installperl> script now places the Perl source files for
535extensions in the architecture-specific library directory, which is
536where the shared libraries for extensions have always been. This
537change is intended to allow administrators to keep the Perl 5.004
538library directory unchanged from a previous version, without running
539the risk of binary incompatibility between extensions' Perl source and
540shared libraries.
541
774d564b 542=head2 Fcntl
543
544New constants in the existing Fcntl modules are now supported,
545provided that your operating system happens to support them:
546
547 F_GETOWN F_SETOWN
2ae324a7 548 O_ASYNC O_DEFER O_DSYNC O_FSYNC O_SYNC
774d564b 549 O_EXLOCK O_SHLOCK
550
0a753a76 551These constants are intended for use with the Perl operators sysopen()
552and fcntl() and the basic database modules like SDBM_File. For the
553exact meaning of these and other Fcntl constants please refer to your
554operating system's documentation for fcntl() and open().
555
556In addition, the Fcntl module now provides these constants for use
557with the Perl operator flock():
558
559 LOCK_SH LOCK_EX LOCK_NB LOCK_UN
560
561These constants are defined in all environments (because where there is
562no flock() system call, Perl emulates it). However, for historical
563reasons, these constants are not exported unless they are explicitly
564requested with the ":flock" tag (e.g. C<use Fcntl ':flock'>).
565
5f05dabc 566=head2 Module Information Summary
567
774d564b 568Brand new modules, arranged by topic rather than strictly
569alphabetically:
570
571 CPAN interface to Comprehensive Perl Archive Network
572 CPAN::FirstTime create a CPAN configuration file
573 CPAN::Nox run CPAN while avoiding compiled extensions
5f05dabc 574
575 IO.pm Top-level interface to IO::* classes
576 IO/File.pm IO::File extension Perl module
577 IO/Handle.pm IO::Handle extension Perl module
578 IO/Pipe.pm IO::Pipe extension Perl module
579 IO/Seekable.pm IO::Seekable extension Perl module
580 IO/Select.pm IO::Select extension Perl module
581 IO/Socket.pm IO::Socket extension Perl module
582
583 Opcode.pm Disable named opcodes when compiling Perl code
584
585 ExtUtils/Embed.pm Utilities for embedding Perl in C programs
586 ExtUtils/testlib.pm Fixes up @INC to use just-built extension
587
5f05dabc 588 FindBin.pm Find path of currently executing program
589
590 Class/Template.pm Structure/member template builder
591 File/stat.pm Object-oriented wrapper around CORE::stat
592 Net/hostent.pm Object-oriented wrapper around CORE::gethost*
593 Net/netent.pm Object-oriented wrapper around CORE::getnet*
594 Net/protoent.pm Object-oriented wrapper around CORE::getproto*
595 Net/servent.pm Object-oriented wrapper around CORE::getserv*
596 Time/gmtime.pm Object-oriented wrapper around CORE::gmtime
597 Time/localtime.pm Object-oriented wrapper around CORE::localtime
598 Time/tm.pm Perl implementation of "struct tm" for {gm,local}time
599 User/grent.pm Object-oriented wrapper around CORE::getgr*
600 User/pwent.pm Object-oriented wrapper around CORE::getpw*
601
774d564b 602 Tie/RefHash.pm Base class for tied hashes with references as keys
7a4c00b4 603
5f05dabc 604 UNIVERSAL.pm Base class for *ALL* classes
605
606=head2 IO
607
608The IO module provides a simple mechanism to load all of the IO modules at one
609go. Currently this includes:
610
611 IO::Handle
612 IO::Seekable
613 IO::File
614 IO::Pipe
615 IO::Socket
616
617For more information on any of these modules, please see its
618respective documentation.
619
620=head2 Math::Complex
621
622The Math::Complex module has been totally rewritten, and now supports
623more operations. These are overloaded:
624
625 + - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
626
627And these functions are now exported:
628
629 pi i Re Im arg
630 log10 logn cbrt root
631 tan cotan asin acos atan acotan
632 sinh cosh tanh cotanh asinh acosh atanh acotanh
633 cplx cplxe
634
0a753a76 635=head2 DB_File
636
637There have been quite a few changes made to DB_File. Here are a few of
638the highlights:
639
640=over
641
642=item *
643
644Fixed a handful of bugs.
645
646=item *
647
648By public demand, added support for the standard hash function exists().
649
650=item *
651
652Made it compatible with Berkeley DB 1.86.
653
654=item *
655
656Made negative subscripts work with RECNO interface.
657
658=item *
659
660Changed the default flags from O_RDWR to O_CREAT|O_RDWR and the default
661mode from 0640 to 0666.
662
663=item *
664
665Made DB_File automatically import the open() constants (O_RDWR,
666O_CREAT etc.) from Fcntl, if available.
667
668=item *
669
670Updated documentation.
671
672=back
673
674Refer to the HISTORY section in DB_File.pm for a complete list of
675changes. Everything after DB_File 1.01 has been added since 5.003.
676
677=head2 Net::Ping
678
679Major rewrite - support added for both udp echo and real icmp pings.
680
5f05dabc 681=head2 Overridden Built-ins
682
683Many of the Perl built-ins returning lists now have
684object-oriented overrides. These are:
685
686 File::stat
687 Net::hostent
688 Net::netent
689 Net::protoent
690 Net::servent
691 Time::gmtime
692 Time::localtime
693 User::grent
694 User::pwent
695
696For example, you can now say
697
698 use File::stat;
699 use User::pwent;
700 $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
701
774d564b 702=head1 Utility Changes
5f05dabc 703
774d564b 704=head2 xsubpp
5f05dabc 705
0a753a76 706=over
707
774d564b 708=item C<void> XSUBs now default to returning nothing
709
710Due to a documentation/implementation bug in previous versions of
711Perl, XSUBs with a return type of C<void> have actually been
712returning one value. Usually that value was the GV for the XSUB,
713but sometimes it was some already freed or reused value, which would
714sometimes lead to program failure.
715
716In Perl 5.004, if an XSUB is declared as returning C<void>, it
717actually returns no value, i.e. an empty list (though there is a
718backward-compatibility exception; see below). If your XSUB really
719does return an SV, you should give it a return type of C<SV *>.
720
721For backward compatibility, I<xsubpp> tries to guess whether a
722C<void> XSUB is really C<void> or if it wants to return an C<SV *>.
723It does so by examining the text of the XSUB: if I<xsubpp> finds
724what looks like an assignment to C<ST(0)>, it assumes that the
725XSUB's return type is really C<SV *>.
5f05dabc 726
0a753a76 727=back
728
729=head1 C Language API Changes
730
731=over
732
733=item C<gv_fetchmethod> and C<perl_call_sv>
734
735The C<gv_fetchmethod> function finds a method for an object, just like
736in Perl 5.003. The GV it returns may be a method cache entry.
737However, in Perl 5.004, method cache entries are not visible to users;
738therefore, they can no longer be passed directly to C<perl_call_sv>.
739Instead, you should use the C<GvCV> macro on the GV to extract its CV,
740and pass the CV to C<perl_call_sv>.
741
742The most likely symptom of passing the result of C<gv_fetchmethod> to
743C<perl_call_sv> is Perl's producing an "Undefined subroutine called"
744error on the I<second> call to a given method (since there is no cache
745on the first call).
746
1e422769 747=item Extended API for manipulating hashes
748
749Internal handling of hash keys has changed. The old hashtable API is
750still fully supported, and will likely remain so. The additions to the
751API allow passing keys as C<SV*>s, so that C<tied> hashes can be given
752real scalars as keys rather than plain strings (non-tied hashes still
753can only use strings as keys). New extensions must use the new hash
754access functions and macros if they wish to use C<SV*> keys. These
755additions also make it feasible to manipulate C<HE*>s (hash entries),
756which can be more efficient. See L<perlguts> for details.
757
0a753a76 758=back
759
5f05dabc 760=head1 Documentation Changes
761
762Many of the base and library pods were updated. These
763new pods are included in section 1:
764
0a753a76 765=over
5f05dabc 766
774d564b 767=item L<perldelta>
5f05dabc 768
71be2cbc 769This document.
5f05dabc 770
71be2cbc 771=item L<perllocale>
5f05dabc 772
71be2cbc 773Locale support (internationalization and localization).
5f05dabc 774
775=item L<perltoot>
776
777Tutorial on Perl OO programming.
778
71be2cbc 779=item L<perlapio>
780
781Perl internal IO abstraction interface.
782
5f05dabc 783=item L<perldebug>
784
785Although not new, this has been massively updated.
786
787=item L<perlsec>
788
789Although not new, this has been massively updated.
790
791=back
792
793=head1 New Diagnostics
794
795Several new conditions will trigger warnings that were
796silent before. Some only affect certain platforms.
2ae324a7 797The following new warnings and errors outline these.
774d564b 798These messages are classified as follows (listed in
799increasing order of desperation):
800
801 (W) A warning (optional).
802 (D) A deprecation (optional).
803 (S) A severe warning (mandatory).
804 (F) A fatal error (trappable).
805 (P) An internal error you should never see (trappable).
806 (X) A very fatal error (non-trappable).
807 (A) An alien error message (not generated by Perl).
5f05dabc 808
0a753a76 809=over
5f05dabc 810
811=item "my" variable %s masks earlier declaration in same scope
812
813(S) A lexical variable has been redeclared in the same scope, effectively
814eliminating all access to the previous instance. This is almost always
815a typographical error. Note that the earlier variable will still exist
816until the end of the scope or until all closure referents to it are
817destroyed.
818
774d564b 819=item %s argument is not a HASH element or slice
820
821(F) The argument to delete() must be either a hash element, such as
822
823 $foo{$bar}
824 $ref->[12]->{"susie"}
825
826or a hash slice, such as
827
828 @foo{$bar, $baz, $xyzzy}
829 @{$ref->[12]}{"susie", "queue"}
830
5f05dabc 831=item Allocation too large: %lx
832
833(X) You can't allocate more than 64K on an MSDOS machine.
834
835=item Allocation too large
836
837(F) You can't allocate more than 2^31+"small amount" bytes.
838
839=item Attempt to free non-existent shared string
840
841(P) Perl maintains a reference counted internal table of strings to
842optimize the storage and access of hash keys and other strings. This
843indicates someone tried to decrement the reference count of a string
844that can no longer be found in the table.
845
846=item Attempt to use reference as lvalue in substr
847
848(W) You supplied a reference as the first argument to substr() used
849as an lvalue, which is pretty strange. Perhaps you forgot to
850dereference it first. See L<perlfunc/substr>.
851
852=item Unsupported function fork
853
854(F) Your version of executable does not support forking.
855
856Note that under some systems, like OS/2, there may be different flavors of
857Perl executables, some of which may support fork, some not. Try changing
858the name you call Perl by to C<perl_>, C<perl__>, and so on.
859
860=item Ill-formed logical name |%s| in prime_env_iter
861
862(W) A warning peculiar to VMS. A logical name was encountered when preparing
863to iterate over %ENV which violates the syntactic rules governing logical
864names. Since it cannot be translated normally, it is skipped, and will not
865appear in %ENV. This may be a benign occurrence, as some software packages
866might directly modify logical name tables and introduce non-standard names,
867or it may indicate that a logical name table has been corrupted.
868
774d564b 869=item Can't use bareword ("%s") as %s ref while "strict refs" in use
870
871(F) Only hard references are allowed by "strict refs". Symbolic references
872are disallowed. See L<perlref>.
873
874=item Constant subroutine %s redefined
875
876(S) You redefined a subroutine which had previously been eligible for
877inlining. See L<perlsub/"Constant Functions"> for commentary and
878workarounds.
879
880=item Died
881
882(F) You passed die() an empty string (the equivalent of C<die "">) or
883you called it with no args and both C<$@> and C<$_> were empty.
884
5f05dabc 885=item Integer overflow in hex number
886
887(S) The literal hex number you have specified is too big for your
888architecture. On a 32-bit architecture the largest hex literal is
8890xFFFFFFFF.
890
891=item Integer overflow in octal number
892
893(S) The literal octal number you have specified is too big for your
894architecture. On a 32-bit architecture the largest octal literal is
895037777777777.
896
774d564b 897=item Name "%s::%s" used only once: possible typo
898
899(W) Typographical errors often show up as unique variable names.
900If you had a good reason for having a unique name, then just mention
901it again somehow to suppress the message (the C<use vars> pragma is
902provided for just this purpose).
903
5f05dabc 904=item Null picture in formline
905
906(F) The first argument to formline must be a valid format picture
907specification. It was found to be empty, which probably means you
908supplied it an uninitialized value. See L<perlform>.
909
910=item Offset outside string
911
912(F) You tried to do a read/write/send/recv operation with an offset
913pointing outside the buffer. This is difficult to imagine.
914The sole exception to this is that C<sysread()>ing past the buffer
915will extend the buffer and zero pad the new area.
916
774d564b 917=item Stub found while resolving method `%s' overloading `%s' in package `%s'
918
919(P) Overloading resolution over @ISA tree may be broken by importing stubs.
920Stubs should never be implicitely created, but explicit calls to C<can>
921may break this.
922
923=item Cannot resolve method `%s' overloading `%s' in package `s'
924
925(P) Internal error trying to resolve overloading specified by a method
926name (as opposed to a subroutine reference).
927
5f05dabc 928=item Out of memory!
929
930(X|F) The malloc() function returned 0, indicating there was insufficient
931remaining memory (or virtual memory) to satisfy the request.
932
933The request was judged to be small, so the possibility to trap it
934depends on the way Perl was compiled. By default it is not trappable.
935However, if compiled for this, Perl may use the contents of C<$^M> as
936an emergency pool after die()ing with this message. In this case the
937error is trappable I<once>.
938
939=item Out of memory during request for %s
940
941(F) The malloc() function returned 0, indicating there was insufficient
942remaining memory (or virtual memory) to satisfy the request. However,
943the request was judged large enough (compile-time default is 64K), so
944a possibility to shut down by trapping this error is granted.
945
946=item Possible attempt to put comments in qw() list
947
774d564b 948(W) qw() lists contain items separated by whitespace; as with literal
949strings, comment characters are not ignored, but are instead treated
950as literal data. (You may have used different delimiters than the
951exclamation marks parentheses shown here; braces are also frequently
952used.)
953
954You probably wrote something like this:
5f05dabc 955
2ae324a7 956 @list = qw(
774d564b 957 a # a comment
5f05dabc 958 b # another comment
774d564b 959 );
5f05dabc 960
961when you should have written this:
962
774d564b 963 @list = qw(
2ae324a7 964 a
5f05dabc 965 b
774d564b 966 );
967
968If you really want comments, build your list the
969old-fashioned way, with quotes and commas:
970
971 @list = (
972 'a', # a comment
973 'b', # another comment
974 );
5f05dabc 975
976=item Possible attempt to separate words with commas
977
774d564b 978(W) qw() lists contain items separated by whitespace; therefore commas
979aren't needed to separate the items. (You may have used different
980delimiters than the parentheses shown here; braces are also frequently
981used.)
5f05dabc 982
2ae324a7 983You probably wrote something like this:
5f05dabc 984
774d564b 985 qw! a, b, c !;
986
987which puts literal commas into some of the list items. Write it without
988commas if you don't want them to appear in your data:
989
990 qw! a b c !;
5f05dabc 991
774d564b 992=item Scalar value @%s{%s} better written as $%s{%s}
993
994(W) You've used a hash slice (indicated by @) to select a single element of
995a hash. Generally it's better to ask for a scalar value (indicated by $).
996The difference is that C<$foo{&bar}> always behaves like a scalar, both when
997assigning to it and when evaluating its argument, while C<@foo{&bar}> behaves
998like a list when you assign to it, and provides a list context to its
999subscript, which can do weird things if you're expecting only one subscript.
5f05dabc 1000
1001=item untie attempted while %d inner references still exist
1002
1003(W) A copy of the object returned from C<tie> (or C<tied>) was still
1004valid when C<untie> was called.
1005
774d564b 1006=item Value of %s construct can be "0"; test with defined()
1007
1008(W) In a conditional expression, you used <HANDLE>, <*> (glob), or
1009C<readdir> as a boolean value. Each of these constructs can return a
1010value of "0"; that would make the conditional expression false, which
1011is probably not what you intended. When using these constructs in
1012conditional expressions, test their values with the C<defined> operator.
1013
1014=item Variable "%s" may be unavailable
1015
1016(W) An inner (nested) I<anonymous> subroutine is inside a I<named>
1017subroutine, and outside that is another subroutine; and the anonymous
1018(innermost) subroutine is referencing a lexical variable defined in
1019the outermost subroutine. For example:
1020
1021 sub outermost { my $a; sub middle { sub { $a } } }
1022
1023If the anonymous subroutine is called or referenced (directly or
1024indirectly) from the outermost subroutine, it will share the variable
1025as you would expect. But if the anonymous subroutine is called or
1026referenced when the outermost subroutine is not active, it will see
1027the value of the shared variable as it was before and during the
1028*first* call to the outermost subroutine, which is probably not what
1029you want.
1030
1031In these circumstances, it is usually best to make the middle
1032subroutine anonymous, using the C<sub {}> syntax. Perl has specific
1033support for shared variables in nested anonymous subroutines; a named
1034subroutine in between interferes with this feature.
1035
1036=item Variable "%s" will not stay shared
1037
1038(W) An inner (nested) I<named> subroutine is referencing a lexical
1039variable defined in an outer subroutine.
1040
1041When the inner subroutine is called, it will probably see the value of
1042the outer subroutine's variable as it was before and during the
1043*first* call to the outer subroutine; in this case, after the first
1044call to the outer subroutine is complete, the inner and outer
1045subroutines will no longer share a common value for the variable. In
1046other words, the variable will no longer be shared.
1047
1048Furthermore, if the outer subroutine is anonymous and references a
1049lexical variable outside itself, then the outer and inner subroutines
1050will I<never> share the given variable.
1051
1052This problem can usually be solved by making the inner subroutine
1053anonymous, using the C<sub {}> syntax. When inner anonymous subs that
1054reference variables in outer subroutines are called or referenced,
1055they are automatically re-bound to the current values of such
1056variables.
1057
1058=item Warning: something's wrong
1059
1060(W) You passed warn() an empty string (the equivalent of C<warn "">) or
1061you called it with no args and C<$_> was empty.
1062
1063=item Got an error from DosAllocMem
5f05dabc 1064
774d564b 1065(P) An error peculiar to OS/2. Most probably you're using an obsolete
1066version of Perl, and this should not happen anyway.
5f05dabc 1067
1068=item Malformed PERLLIB_PREFIX
1069
1070(F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
1071
1072 prefix1;prefix2
1073
1074or
1075
1076 prefix1 prefix2
1077
1078with non-empty prefix1 and prefix2. If C<prefix1> is indeed a prefix of
1079a builtin library search path, prefix2 is substituted. The error may appear
1080if components are not found, or are too long. See L<perlos2/"PERLLIB_PREFIX">.
1081
1082=item PERL_SH_DIR too long
1083
1084(F) An error peculiar to OS/2. PERL_SH_DIR is the directory to find the
1085C<sh>-shell in. See L<perlos2/"PERL_SH_DIR">.
1086
1087=item Process terminated by SIG%s
1088
1089(W) This is a standard message issued by OS/2 applications, while *nix
1090applications die in silence. It is considered a feature of the OS/2
1091port. One can easily disable this by appropriate sighandlers, see
1092L<perlipc/"Signals">. See L<perlos2/"Process terminated by SIGTERM/SIGINT">.
1093
1094=back
1095
1096=head1 BUGS
1097
774d564b 1098If you find what you think is a bug, you might check the headers of
1099recently posted articles in the comp.lang.perl.misc newsgroup.
1100There may also be information at http://www.perl.com/perl/, the Perl
1101Home Page.
5f05dabc 1102
1103If you believe you have an unreported bug, please run the B<perlbug>
9607fc9c 1104program included with your release. Make sure you trim your bug down
1105to a tiny but sufficient test case. Your bug report, along with the
1106output of C<perl -V>, will be sent off to <F<perlbug@perl.com>> to be
1107analysed by the Perl porting team.
5f05dabc 1108
1109=head1 SEE ALSO
1110
1111The F<Changes> file for exhaustive details on what changed.
1112
1113The F<INSTALL> file for how to build Perl. This file has been
1114significantly updated for 5.004, so even veteran users should
1115look through it.
1116
1117The F<README> file for general stuff.
1118
1119The F<Copying> file for copyright information.
1120
1121=head1 HISTORY
1122
1123Constructed by Tom Christiansen, grabbing material with permission
1124from innumerable contributors, with kibitzing by more than a few Perl
1125porters.
1126
2ae324a7 1127Last update: Sat Mar 8 19:51:26 EST 1997