Patch for perl.pod
[p5sagit/p5-mst-13.2.git] / pod / perldelta.pod
index 04e9a45..46bd59b 100644 (file)
@@ -27,6 +27,55 @@ might have symbol conflicts if you embed Perl in another application,
 just as in the 5.003 release.  By default, binary compatibility
 is preserved at the expense of symbol table pollution.
 
+=head2 Subroutine arguments created only when they're modified
+
+In Perl 5.004, nonexistent array and hash elements used as subroutine
+parameters are brought into existence only if they are actually
+assigned to (via C<@_>).
+
+Earlier versions of Perl vary in their handling of such arguments.
+Perl versions 5.002 and 5.003 always brought them into existence.
+Perl versions 5.000, 5.001, and 5.002 brought them into existence only
+if they were not the first argument (which was almost certainly a
+bug).  Earlier versions of Perl never brought them into existence.
+
+For example, given this code:
+
+     undef @a; undef %a;
+     sub show { print $_[0] };
+     sub change { $_[0]++ };
+     show($a[2]);
+     change($a{b});
+
+After this code executes in Perl 5.004, $a{b} exists but $a[2] does
+not.  In Perl 5.002 and 5.003, both $a{b} and $a[2] would have existed
+(but $a[2]'s value would have been undefined).
+
+=head2 Fixed Parsing of $$<digit>, &$<digit>, etc.
+
+A bug in previous versions of Perl 5.0 prevented proper parsing of
+numeric special variables as symbolic references.  That bug has been
+fixed.  As a result, the string "$$0" is no longer equivalent to
+C<$$."0">, but rather to C<${$0}>.  To get the old behavior, change
+"$$" followed by a digit to "${$}".
+
+=head2 No Resetting of $. on Implicit Close
+
+The documentation for Perl 5.0 has always stated that C<$.> is I<not>
+reset when an already-open file handle is re-opened with no intervening
+call to C<close>.  Due to a bug, perl versions 5.000 through 5.0003
+I<did> reset C<$.> under that circumstance; Perl 5.004 does not.
+
+=head2 Changes to Tainting Checks
+
+A bug in previous versions may have failed to detect some insecure
+conditions when taint checks are turned on. (Taint checks are used
+in setuid or setgid scripts, or when explicitly turned on with the
+C<-T> invocation option.) Although it's unlikely, this may cause a
+previously-working script to now fail -- which should be construed
+as a blessing, since that indicates a potentially-serious security
+hole was just plugged.
+
 =head2 New Opcode Module and Revised Safe Module
 
 A new Opcode module supports the creation, manipulation and
@@ -34,13 +83,25 @@ application of opcode masks.  The revised Safe module has a new API
 and is implemented using the new Opcode module.  Please read the new
 Opcode and Safe documentation.
 
-=head2 Internal Change: FileHandle Deprecated
+=head2 Embedding Improvements
+
+In older versions of Perl it was not possible to create more than one
+Perl interpreter instance inside a single process without leaking like a
+sieve and/or crashing.  The bugs that caused this behavior have all been
+fixed.  However, you still must take care when embedding Perl in a C
+program.  See the updated perlembed manpage for tips on how to manage
+your interpreters.
 
-Filehandles are now stored internally as type IO::Handle.
-Although C<use FileHandle> and C<*STDOUT{FILEHANDLE}>
-are still supported for backwards compatibility,
-C<use IO::Handle> (or C<IO::Seekable> or C<IO::File>) and
-C<*STDOUT{IO}> are the way of the future.
+=head2 Internal Change: FileHandle Class Based on IO::* Classes
+
+File handles are now stored internally as type IO::Handle.  The
+FileHandle module is still supported for backwards compatibility, but
+it is now merely a front end to the IO::* modules -- specifically,
+IO::Handle, IO::Seekable, and IO::File.  We suggest, but do not
+require, that you use the IO::* modules in new code.
+
+In harmony with this change, C<*GLOB{FILEHANDLE}> is now a
+backward-compatible synonym for C<*STDOUT{IO}>.
 
 =head2 Internal Change: PerlIO internal IO abstraction interface
 
@@ -54,8 +115,8 @@ the F<INSTALL> file for how to use it.
 
 =item $^E
 
-Extended error message under some platforms ($EXTENDED_OS_ERROR
-if you C<use English>).
+Extended error message on some platforms.  (Also known as
+$EXTENDED_OS_ERROR if you C<use English>).
 
 =item $^H
 
@@ -91,16 +152,21 @@ This now works.  (e.g. C<delete @ENV{'PATH', 'MANPATH'}>)
 
 =item flock
 
-is now supported on more platforms, and prefers fcntl
-to lockf when emulating.
+is now supported on more platforms, prefers fcntl to lockf when
+emulating, and always flushes before (un)locking.
+
+=item printf and sprintf
+
+now support "%i" as a synonym for "%d", and the "h" modifier.
+So "%hi" means "short integer in decimal", and "%ho" means
+"unsigned short integer as octal".
 
 =item keys as an lvalue
 
 As an lvalue, C<keys> allows you to increase the number of hash buckets
-allocated for the given associative array.  This can gain you a measure
-of efficiency if you know the hash is going to get big.  (This is
-similar to pre-extending an array by assigning a larger number to
-$#array.)  If you say
+allocated for the given hash.  This can gain you a measure of efficiency if
+you know the hash is going to get big.  (This is similar to pre-extending
+an array by assigning a larger number to $#array.)  If you say
 
     keys %hash = 200;
 
@@ -116,7 +182,7 @@ as trying has no effect).
 You can now use my() (with or without the parentheses) in the control
 expressions of control structures such as:
 
-    while (my $line = <>) {
+    while (defined(my $line = <>)) {
         $line = lc $line;
     } continue {
         print $line;
@@ -185,6 +251,19 @@ function has no prototype).  FUNCTION is a reference to or the name of the
 function whose prototype you want to retrieve.
 (Not actually new; just never documented before.)
 
+=item srand
+
+The default seed for C<srand>, which used to be C<time>, has been changed.
+Now it's a heady mix of difficult-to-predict system-dependent values,
+which should be sufficient for most everyday purposes.
+
+Previous to version 5.004, calling C<rand> without first calling C<srand>
+would yield the same sequence of random numbers on most or all machines.
+Now, when perl sees that you're calling C<rand> and haven't yet called
+C<srand>, it calls C<srand> with the default seed. You should still call
+C<srand> manually if your code might ever be run on a pre-5.004 system,
+of course, or if you want a seed other than the default.
+
 =item $_ as Default
 
 Functions documented in the Camel to default to $_ now in
@@ -200,10 +279,17 @@ string in some way.  This change makes it practical to chain C<m//g>
 matches together in conjunction with ordinary matches using the C<\G>
 zero-width assertion.  See L<perlop> and L<perlre>.
 
+=item C<m//x> ignores whitespace before ?*+{}
+
+The C<m//x> construct has always been intended to ignore all unescaped
+whitespace.  However, before Perl 5.004, whitespace had the effect of
+esacping repeat modifier like "*" or "?".  For example, C</a *b/x> was
+(mis)interpreted as C</a\*b/x>.  This bug has been fixed in 5.004.
+
 =item nested C<sub{}> closures work now
 
-Prior to the 5.004 release, nested anonymous functions 
-didn't work right.  They do now.
+Prior to the 5.004 release, nested anonymous functions didn't work
+right.  They do now.
 
 =item formats work right on changing lexicals
 
@@ -219,7 +305,7 @@ before, and is fine now:
        $i
     .
        write;
-    } 
+    }
 
 =back
 
@@ -232,7 +318,7 @@ are inherited by all other classes:
 
 =item isa(CLASS)
 
-C<isa> returns I<true> if its object is blessed into a sub-class of C<CLASS>
+C<isa> returns I<true> if its object is blessed into a subclass of C<CLASS>
 
 C<isa> is also exportable and can be called as a sub with two arguments. This
 allows the ability to check what a reference points to. Example:
@@ -262,34 +348,6 @@ C<VERSION> form of C<use>.
     # implies:
     A->VERSION(1.2);
 
-=item class()
-
-C<class> returns the class name of its object.
-
-=item is_instance()
-
-C<is_instance> returns true if its object is an instance of some
-class, false if its object is the class (package) itself. Example
-
-    A->is_instance();       # False
-
-    $var = 'A';
-    $var->is_instance();    # False
-
-    $ref = bless [], 'A';
-    $ref->is_instance();    # True
-
-This can be useful for methods that wish to easily distinguish
-whether they were invoked as class or as instance methods.
-
-    sub some_meth {
-       my $classname = shift;
-       if ($classname->is_instance()) {
-           die "unexpectedly called as instance not class method";
-       } 
-       .....
-    } 
-
 =back
 
 B<NOTE:> C<can> directly uses Perl's internal code for method lookup, and
@@ -313,9 +371,9 @@ This is the constructor for the class.  That means it is expected to
 return an object of some sort. The reference can be used to
 hold some internal information.
 
-    sub TIEHANDLE { 
-       print "<shout>\n"; 
-       my $i; 
+    sub TIEHANDLE {
+       print "<shout>\n";
+       my $i;
        return bless \$i, shift;
     }
 
@@ -325,46 +383,122 @@ This method will be triggered every time the tied handle is printed to.
 Beyond its self reference it also expects the list that was passed to
 the print function.
 
-    sub PRINT { 
-       $r = shift; 
-       $$r++; 
+    sub PRINT {
+       $r = shift;
+       $$r++;
        return print join( $, => map {uc} @_), $\;
     }
 
+=item READ this LIST
+
+This method will be called when the handle is read from via the C<read>
+or C<sysread> functions.
+
+    sub READ {
+       $r = shift;
+       my($buf,$len,$offset) = @_;
+       print "READ called, \$buf=$buf, \$len=$len, \$offset=$offset";
+    }
+
 =item READLINE this
 
 This method will be called when the handle is read from. The method
 should return undef when there is no more data.
 
-    sub READLINE { 
-       $r = shift; 
-       return "PRINT called $$r times\n"; 
+    sub READLINE {
+       $r = shift;
+       return "PRINT called $$r times\n"
     }
 
+=item GETC this
+
+This method will be called when the C<getc> function is called.
+
+    sub GETC { print "Don't GETC, Get Perl"; return "a"; }
+
 =item DESTROY this
 
 As with the other types of ties, this method will be called when the
 tied handle is about to be destroyed. This is useful for debugging and
 possibly for cleaning up.
 
-    sub DESTROY { 
+    sub DESTROY {
        print "</shout>\n";
     }
 
 =back
 
-=item Efficiency Enhancements
+=head2 Malloc Enhancements
+
+Four new compilation flags are recognized by malloc.c.  (They have no
+effect if perl is compiled with system malloc().)
+
+=over
+
+=item -DDEBUGGING_MSTATS
+
+If perl is compiled with C<DEBUGGING_MSTATS> defined, you can print
+memory statistics at runtime by running Perl thusly:
+
+  env PERL_DEBUG_MSTATS=2 perl your_script_here
+
+The value of 2 means to print statistics after compilation and on
+exit; with a value of 1, the statistics ares printed only on exit.
+(If you want the statistics at an arbitrary time, you'll need to
+install the optional module Devel::Peek.)
+
+=item -DEMERGENCY_SBRK
+
+If this macro is defined, running out of memory need not be a fatal
+error: a memory pool can allocated by assigning to the special
+variable C<$^M>.  See L<"$^M">.
+
+=item -DPACK_MALLOC
+
+Perl memory allocation is by bucket with sizes close to powers of two.
+Because of these malloc overhead may be big, especially for data of
+size exactly a power of two.  If C<PACK_MALLOC> is defined, perl uses
+a slightly different algorithm for small allocations (up to 64 bytes
+long), which makes it possible to have overhead down to 1 byte for
+allocations which are powers of two (and appear quite often).
 
-All hash keys with the same string are only allocated once, so
-even if you have 100 copies of the same hash, the immutable keys
-never have to be re-allocated.
+Expected memory savings (with 8-byte alignment in C<alignbytes>) is
+about 20% for typical Perl usage.  Expected slowdown due to additional
+malloc overhead is in fractions of a percent (hard to measure, because
+of the effect of saved memory on speed).
+
+=item -DTWO_POT_OPTIMIZE
+
+Similarly to C<PACK_MALLOC>, this macro improves allocations of data
+with size close to a power of two; but this works for big allocations
+(starting with 16K by default).  Such allocations are typical for big
+hashes and special-purpose scripts, especially image processing.
+
+On recent systems, the fact that perl requires 2M from system for 1M
+allocation will not affect speed of execution, since the tail of such
+a chunk is not going to be touched (and thus will not require real
+memory).  However, it may result in a premature out-of-memory error.
+So if you will be manipulating very large blocks with sizes close to
+powers of two, it would be wise to define this macro.
+
+Expected saving of memory is 0-100% (100% in applications which
+require most memory in such 2**n chunks); expected slowdown is
+negligible.
+
+=back
+
+=head2 Miscellaneous Efficiency Enhancements
 
 Functions that have an empty prototype and that do nothing but return
 a fixed value are now inlined (e.g. C<sub PI () { 3.14159 }>).
 
+Each unique hash key is only allocated once, no matter how many hashes
+have an entry with that key.  So even if you have 100 copies of the
+same hash, the hash keys never have to be reallocated.
+
 =head1 Pragmata
 
-Three new pragmatic modules exist:
+Four new pragmatic modules exist:
 
 =over
 
@@ -401,17 +535,36 @@ See L<perllocale> for more information.
 
 Disable unsafe opcodes, or any named opcodes, when compiling Perl code.
 
+=item use vmsish
+
+Enable VMS-specific language features.  Currently, there are three
+VMS-specific features available: 'status', which makes C<$?> and
+C<system> return genuine VMS status values instead of emulating POSIX;
+'exit', which makes C<exit> take a genuine VMS status value instead of
+assuming that C<exit 1> is an error; and 'time', which makes all times
+relative to the local time zone, in the VMS tradition.
+
 =back
 
 =head1 Modules
 
+=head2 Installation Directories
+
+The I<installperl> script now places the Perl source files for
+extensions in the architecture-specific library directory, which is
+where the shared libraries for extensions have always been.  This
+change is intended to allow administrators to keep the Perl 5.004
+library directory unchanged from a previous version, without running
+the risk of binary incompatibility between extensions' Perl source and
+shared libraries.
+
 =head2 Fcntl
 
 New constants in the existing Fcntl modules are now supported,
 provided that your operating system happens to support them:
 
     F_GETOWN F_SETOWN
-    O_ASYNC O_DEFER O_DSYNC O_FSYNC O_SYNC 
+    O_ASYNC O_DEFER O_DSYNC O_FSYNC O_SYNC
     O_EXLOCK O_SHLOCK
 
 These constants are intended for use with the Perl operators sysopen()
@@ -451,7 +604,6 @@ alphabetically:
     ExtUtils/Embed.pm    Utilities for embedding Perl in C programs
     ExtUtils/testlib.pm  Fixes up @INC to use just-built extension
 
-    Fatal.pm             Make do-or-die equivalents of functions
     FindBin.pm           Find path of currently executing program
 
     Class/Template.pm    Structure/member template builder
@@ -611,6 +763,17 @@ C<perl_call_sv> is Perl's producing an "Undefined subroutine called"
 error on the I<second> call to a given method (since there is no cache
 on the first call).
 
+=item Extended API for manipulating hashes
+
+Internal handling of hash keys has changed.  The old hashtable API is
+still fully supported, and will likely remain so.  The additions to the
+API allow passing keys as C<SV*>s, so that C<tied> hashes can be given
+real scalars as keys rather than plain strings (non-tied hashes still
+can only use strings as keys).  New extensions must use the new hash
+access functions and macros if they wish to use C<SV*> keys.  These
+additions also make it feasible to manipulate C<HE*>s (hash entries),
+which can be more efficient.  See L<perlguts> for details.
+
 =back
 
 =head1 Documentation Changes
@@ -650,7 +813,7 @@ Although not new, this has been massively updated.
 
 Several new conditions will trigger warnings that were
 silent before.  Some only affect certain platforms.
-The following new warnings and errors outline these.  
+The following new warnings and errors outline these.
 These messages are classified as follows (listed in
 increasing order of desperation):
 
@@ -809,7 +972,7 @@ used.)
 
 You probably wrote something like this:
 
-    @list = qw( 
+    @list = qw(
         a # a comment
         b # another comment
     );
@@ -817,7 +980,7 @@ You probably wrote something like this:
 when you should have written this:
 
     @list = qw(
-        a 
+        a
         b
     );
 
@@ -836,7 +999,7 @@ aren't needed to separate the items. (You may have used different
 delimiters than the parentheses shown here; braces are also frequently
 used.)
 
-You probably wrote something like this: 
+You probably wrote something like this:
 
     qw! a, b, c !;
 
@@ -957,10 +1120,10 @@ There may also be information at http://www.perl.com/perl/, the Perl
 Home Page.
 
 If you believe you have an unreported bug, please run the B<perlbug>
-program included with your release.  Make sure you trim your bug
-down to a tiny but sufficient test case.  Your bug report, along
-with the output of C<perl -V>, will be sent off to perlbug@perl.com
-to be analysed by the Perl porting team.
+program included with your release.  Make sure you trim your bug down
+to a tiny but sufficient test case.  Your bug report, along with the
+output of C<perl -V>, will be sent off to <F<perlbug@perl.com>> to be
+analysed by the Perl porting team.
 
 =head1 SEE ALSO
 
@@ -980,4 +1143,4 @@ Constructed by Tom Christiansen, grabbing material with permission
 from innumerable contributors, with kibitzing by more than a few Perl
 porters.
 
-Last update: Tue Jan 14 14:03:02 EST 1997
+Last update: Sat Mar  8 19:51:26 EST 1997