![]() |
|
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). Group vector changeable with
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
used to print something like "timenowis881399109|4", but now (and in perl4) prints "4|4".
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 -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.
The new restrictions when tainting include:
A new Opcode module supports the creation, manipulation and 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.
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.
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, *GLOB{FILEHANDLE} is now just a
backward-compatible synonym for *GLOB{IO}.
It is now possible to build Perl with AT&T's sfio IO package instead of stdio. See perlapio for more details, and the INSTALL file for how to use it.
A subroutine reference may now be suffixed with an arrow and a (possibly empty) parameter list. This syntax denotes a call of the referenced subroutine, with the given parameters (if any).
This new syntax follows the pattern of $hashref->{FOO} and $aryref->[$foo]:
You may now write &$subref($foo) as $subref->($foo). All
these arrow terms may be chained; thus, &{$table->{FOO}}($bar) may now
be written $table->{FOO}->($bar).
package; directive). Like __FILE__ and __LINE__,
__PACKAGE__ does not interpolate into strings.use
English).
use strict. See the
documentation of strict for more details. Not actually new, but newly
documented. Because it is intended for internal use by Perl core components, there is no use
English long name for this variable.
By default, running out of memory it is not trappable. However, if compiled for this,
Perl may use the contents of $^M as an emergency pool after die()ing with
this message. Suppose that your Perl were compiled with -DPERL_EMERGENCY_SBRK and used
Perl's malloc. Then
|
would allocate a 64K buffer for use when in emergency. See the INSTALL file for
information on how to enable this option. As a disincentive to casual use of this advanced
feature, there is no use English long name for this variable.
delete @ENV{'PATH', 'MANPATH'})
Perl now implements these functions itself; it doesn't use the C library function sprintf() any more, except for floating-point numbers, and even then only known flags are allowed. As a result, it is now possible to know which conversions and flags will work, and what they will do.
The new conversions in Perl's sprintf() are:
|
The new flags that go between the % and the conversion are:
|
Also, where a number would appear in the flags, an asterisk ("*") may be used instead, in which case Perl uses the next item in the parameter list as the given number (that is, as the field width or precision). If a field width obtained through "*" is negative, it has the same effect as the '-' flag: left-justification.
See perlfunc/sprintf for a complete list of conversion and flags.
As an lvalue, keys allows you to increase the number of hash buckets
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
|
then %hash will have at least 200 buckets allocated for it. These buckets
will be retained even if you do %hash = (); use undef %hash if
you want to free the storage while %hash is still in scope. You can't shrink
the number of buckets allocated for the hash using keys in this way (but you
needn't worry about doing this by accident, as trying has no effect).
You can now use my() (with or without the parentheses) in the control expressions of control structures such as:
|
Also, you can declare a foreach loop control variable as lexical by preceding it with the word "my". For example, in:
|
$i is a lexical variable, and the scope of $i extends to the end of the loop, but not beyond it.
Note that you still cannot use my() on global punctuation variables such as $_ and the like.
A new format 'w' represents a BER compressed integer (as defined in ASN.1). Its format is a sequence of one or more bytes, each of which provides seven bits of the total value, with the most significant first. Bit eight of each byte is set, except for the last byte, in which bit eight is clear.
If 'p' or 'P' are given undef as values, they now generate a NULL pointer.
Both pack() and unpack() now fail when their templates contain invalid types. (Invalid types used to be ignored.)
use is a number, it is treated as a version number
instead of a module name. If the version of the Perl interpreter is less than VERSION,
then an error message is printed and Perl exits immediately. Because use
occurs at compile time, this check happens immediately during the compilation process,
unlike require VERSION, which waits until runtime for the check. This is
often useful if you need to check the current Perl version before useing
library modules which have changed in incompatible ways from older versions of Perl. (We
try not to do this more than we have to.)
If the VERSION argument is present between Module and LIST, then the use
will call the VERSION method in class Module with the given version as an argument. The
default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is
larger than the value of the variable $Module::VERSION. (Note that there is not a comma
after VERSION!)
This version-checking mechanism is similar to the one currently used in the Exporter module, but it is faster and can be used with modules that don't use the Exporter. It is the recommended method for new code.
undef if the 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.)
The default seed for srand, which used to be 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 rand without first calling srand
would yield the same sequence of random numbers on most or all machines. Now, when perl
sees that you're calling rand and haven't yet called srand, it
calls srand with the default seed. You should still call 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.
m//gc does not
reset search position on failure
m//g match iteration construct has always reset its target string's
search position (which is visible through the pos operator) when a match
fails; as a result, the next m//g match after a failure starts again at the
beginning of the string. With Perl 5.004, this reset may be disabled by adding the
"c" (for "continue") modifier, i.e. m//gc. This feature,
in conjunction with the \G zero-width assertion, makes it possible to chain
matches together. See perlop
and perlre.
m//x ignores
whitespace before ?*+{}
m//x construct has always been intended to ignore all unescaped
whitespace. However, before Perl 5.004, whitespace had the effect of escaping repeat
modifiers like "*" or "?"; for example, /a *b/x was (mis)interpreted
as /a\*b/x. This bug has been fixed in 5.004.
sub{} closures work now
Just like anonymous functions that contain lexical variables that change (like a
lexical index variable for a foreach loop), formats now work properly. For
example, this silently failed before (printed only zeros), but is fine now:
|
However, it still fails (without a warning) if the foreach is within a subroutine:
|
The UNIVERSAL package automatically contains the following methods that are
inherited by all other classes:
isa returns true if its object is blessed into a subclass of CLASS
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:
|
can checks to see if its object has a method called METHOD, if
it does then a reference to the sub is returned; if it does not then undef is
returned.
VERSION returns the version number of the class (package). If the NEED
argument is given then it will check that the current version (as defined by the $VERSION
variable in the given package) not less than NEED; it will die if this is not the case.
This method is normally called as a class method. This method is called automatically by
the VERSION form of use.
|
NOTE: can directly uses Perl's internal code for method lookup, and isa
uses a very similar method and caching strategy. This may cause strange effects if the Perl
code dynamically changes @ISA in any package.
You may add other methods to the UNIVERSAL class via Perl or XS code. You do not need to use
UNIVERSAL in order to make these methods available to your program. This is necessary
only if you wish to have isa available as a plain subroutine in the current
package.
See perltie for other kinds of tie()s.
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.
|
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.
|
This method will be triggered every time the tied handle is printed to with the printf()
function. Beyond its self reference it also expects the format and list that was passed to
the printf function.
|
This method will be called when the handle is read from via the read or sysread
functions.
|
This method will be called when the handle is read from. The method should return undef when there is no more data.
|
This method will be called when the getc function is called.
|
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.
|
If perl is compiled with the malloc included with the perl distribution (that is, if perl
-V:d_mymalloc is 'define') then you can print memory statistics at runtime by running
Perl thusly:
|
The value of 2 means to print statistics after compilation and on exit; with a value of 1, the statistics are printed only on exit. (If you want the statistics at an arbitrary time, you'll need to install the optional module Devel::Peek.)
Three new compilation flags are recognized by malloc.c. (They have no effect if perl is compiled with system malloc().)
$^M. See "$^M".
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 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).
Expected memory savings (with 8-byte alignment in 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).
Similarly to 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.
Functions that have an empty prototype and that do nothing but return a fixed value are now
inlined (e.g. 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.
Support for the following operating systems is new in Perl 5.004.
Perl 5.004 now includes support for building a "native" perl under Windows NT, using the Microsoft Visual C++ compiler (versions 2.0 and above) or the Borland C++ compiler (versions 5.02 and above). The resulting perl can be used under Windows 95 (if it is installed in the same directory locations as it got installed in Windows NT). This port includes support for perl extension building tools like MakeMaker and h2xs, so that many extensions available on the Comprehensive Perl Archive Network (CPAN) can now be readily built under Windows NT. See http://www.perl.com/ for more information on CPAN and README.win32 in the perl distribution for more details on how to get started with building this port.
There is also support for building perl under the Cygwin32 environment. Cygwin32 is a set of GNU tools that make it possible to compile and run many Unix programs under Windows NT by providing a mostly Unix-like interface for compilation and execution. See README.cygwin32 in the perl distribution for more details on this port and how to obtain the Cygwin32 toolkit.
See README.plan9 in the perl distribution.
See README.qnx in the perl distribution.
See README.amigaos in the perl distribution.
Six new pragmatic modules exist:
require MODULE until someone calls one of the specified subroutines
(which must be exported by MODULE). This pragma should be used with caution, and only when
necessary.
Looks for MakeMaker-like 'blib' directory structure starting in dir (or current directory) and working back up to five levels of parent directories.
Intended for use on command line with -M option as a way of testing arbitrary scripts against an uninstalled version of a package.
Tells the compiler to enable (or disable) the use of POSIX locales for builtin operations.
When use locale is in effect, the current LC_CTYPE locale is used for
regular expressions and case mapping; LC_COLLATE for string ordering; and LC_NUMERIC for
numeric formatting in printf and sprintf (but not in print). LC_NUMERIC is always
used in write, since lexical scoping of formats is problematic at best.
Each use locale or no locale affects statements to the end of
the enclosing BLOCK or, if not inside a BLOCK, to the end of the current file. Locales can
be switched and queried with POSIX::setlocale().
See perllocale for more information.
$? and system return genuine
VMS status values instead of emulating POSIX; 'exit', which makes exit take a
genuine VMS status value instead of assuming that exit 1 is an error; and
'time', which makes all times relative to the local time zone, in the VMS tradition.Though Perl 5.004 is compatible with almost all modules that work with Perl 5.003, there are a few exceptions:
|
Also, the majordomo mailing list program, version 1.94.1, doesn't work with Perl 5.004 (nor with perl 4), because it executes an invalid regular expression. This bug is fixed in majordomo version 1.94.2.
The 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.
Brand new modules, arranged by topic rather than strictly alphabetically:
|
New constants in the existing Fcntl modules are now supported, provided that your operating system happens to support them:
|
These constants are intended for use with the Perl operators sysopen() and fcntl() and the basic database modules like SDBM_File. For the exact meaning of these and other Fcntl constants please refer to your operating system's documentation for fcntl() and open().
In addition, the Fcntl module now provides these constants for use with the Perl operator flock():
|
These constants are defined in all environments (because where there is no flock() system
call, Perl emulates it). However, for historical reasons, these constants are not exported
unless they are explicitly requested with the ":flock" tag (e.g. use Fcntl
':flock').
The IO module provides a simple mechanism to load all the IO modules at one go. Currently this includes:
|
For more information on any of these modules, please see its respective documentation.
The Math::Complex module has been totally rewritten, and now supports more operations. These are overloaded:
|
And these functions are now exported:
|
This new module provides a simpler interface to parts of Math::Complex for those who need trigonometric functions only for real numbers.
There have been quite a few changes made to DB_File. Here are a few of the highlights:
Refer to the HISTORY section in DB_File.pm for a complete list of changes. Everything after DB_File 1.01 has been added since 5.003.
Major rewrite - support added for both udp echo and real icmp pings.
Many of the Perl builtins returning lists now have object-oriented overrides. These are:
|
For example, you can now say
|
void XSUBs now
default to returning nothing
Due to a documentation/implementation bug in previous versions of Perl, XSUBs with a
return type of void have actually been returning one value. Usually that
value was the GV for the XSUB, but sometimes it was some already freed or reused value,
which would sometimes lead to program failure.
In Perl 5.004, if an XSUB is declared as returning void, it actually
returns no value, i.e. an empty list (though there is a backward-compatibility exception;
see below). If your XSUB really does return an SV, you should give it a return type of SV
*.
For backward compatibility, xsubpp tries to guess whether a void
XSUB is really void or if it wants to return an SV *. It does so
by examining the text of the XSUB: if xsubpp finds what looks like an assignment to
ST(0), it assumes that the XSUB's return type is really SV *.
gv_fetchmethod and perl_call_sv
The gv_fetchmethod function finds a method for an object, just like in
Perl 5.003. The GV it returns may be a method cache entry. However, in Perl 5.004, method
cache entries are not visible to users; therefore, they can no longer be passed directly
to perl_call_sv. Instead, you should use the GvCV macro on the
GV to extract its CV, and pass the CV to perl_call_sv.
The most likely symptom of passing the result of gv_fetchmethod to perl_call_sv
is Perl's producing an "Undefined subroutine called" error on the second
call to a given method (since there is no cache on the first call).
perl_eval_pv
SV*s,
so that tied hashes can be given real scalars as keys rather than plain
strings (nontied hashes still can only use strings as keys). New extensions must use the
new hash access functions and macros if they wish to use SV* keys. These
additions also make it feasible to manipulate HE*s (hash entries), which can
be more efficient. See perlguts
for details.Many of the base and library pods were updated. These new pods are included in section 1:
Several new conditions will trigger warnings that were silent before. Some only affect certain platforms. The following new warnings and errors outline these. These messages are classified as follows (listed in increasing order of desperation):
|
(F) The argument to delete() must be either a hash element, such as
|
or a hash slice, such as
|
Foo::, but the compiler saw
no other uses of that namespace before that point. Perhaps you need to predeclare a
package?
sort { &func }
@x instead of sort func @x.
die "")
or you called it with no args and both $@ and $_ were empty.
$A::B). You've exceeded
Perl's limits. Future versions of Perl are likely to eliminate these arbitrary
limitations.
print <<EOF;).
glob and <*.c>.
This may mean that your csh (C shell) is broken. If so, you should change all of the
csh-related variables in config.sh: If you have tcsh, make the variables refer to it as if
it were csh (e.g. full_csh='/usr/bin/tcsh'); otherwise, make them all empty
(except that d_csh should be 'undef') so that Perl will think
csh is missing. In either case, after editing config.sh, run ./Configure -S
and rebuild Perl.
use vars pragma is provided for just this purpose).
sysread()ing
past the buffer will extend the buffer and zero pad the new area.
(X|F) The malloc() function returned 0, indicating there was insufficient remaining memory (or virtual memory) to satisfy the request.
The request was judged to be small, so the possibility to trap it depends on the way
Perl was compiled. By default it is not trappable. However, if compiled for this, Perl may
use the contents of $^M as an emergency pool after die()ing with this
message. In this case the error is trappable once.
(W) qw() lists contain items separated by whitespace; as with literal strings, comment characters are not ignored, but are instead treated as literal data. (You may have used different delimiters than the parentheses shown here; braces are also frequently used.)
You probably wrote something like this:
|
when you should have written this:
|
If you really want comments, build your list the old-fashioned way, with quotes and commas:
|
(W) qw() lists contain items separated by whitespace; therefore commas 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:
|
which puts literal commas into some of the list items. Write it without commas if you don't want them to appear in your data:
|
$foo{&bar}
always behaves like a scalar, both when assigning to it and when evaluating its argument,
while @foo{&bar} behaves like a list when you assign to it, and provides
a list context to its subscript, which can do weird things if you're expecting only one
subscript.
can may break this.
tie (or tied) was still
valid when untie was called.
(F) Your version of executable does not support forking.
Note that under some systems, like OS/2, there may be different flavors of Perl
executables, some of which may support fork, some not. Try changing the name you call Perl
by to perl_, perl__, and so on.
(D) Perl versions before 5.004 misinterpreted any type marker followed by "$" and a digit. For example, "$$0" was incorrectly taken to mean "${$}0" instead of "${$0}". This bug is (mostly) fixed in Perl 5.004.
However, the developers of Perl 5.004 could not fix this bug completely, because at least two widely-used modules depend on the old meaning of "$$0" in a string. So Perl 5.004 still interprets "$$<digit>" in the old (broken) way inside strings; but it generates this message as a warning. And in Perl 5.005, this special treatment will cease.
each(),
or readdir() as a boolean value. Each of these constructs can return a value
of "0"; that would make the conditional expression false, which is probably not
what you intended. When using these constructs in conditional expressions, test their
values with the defined operator.
(W) An inner (nested) anonymous subroutine is inside a named subroutine, and outside that is another subroutine; and the anonymous (innermost) subroutine is referencing a lexical variable defined in the outermost subroutine. For example:
|
If the anonymous subroutine is called or referenced (directly or indirectly) from the outermost subroutine, it will share the variable as you would expect. But if the anonymous subroutine is called or referenced when the outermost subroutine is not active, it will see the value of the shared variable as it was before and during the *first* call to the outermost subroutine, which is probably not what you want.
In these circumstances, it is usually best to make the middle subroutine anonymous,
using the sub {} syntax. Perl has specific support for shared variables in
nested anonymous subroutines; a named subroutine in between interferes with this feature.
(W) An inner (nested) named subroutine is referencing a lexical variable defined in an outer subroutine.
When the inner subroutine is called, it will probably see the value of the outer subroutine's variable as it was before and during the *first* call to the outer subroutine; in this case, after the first call to the outer subroutine is complete, the inner and outer subroutines will no longer share a common value for the variable. In other words, the variable will no longer be shared.
Furthermore, if the outer subroutine is anonymous and references a lexical variable outside itself, then the outer and inner subroutines will never share the given variable.
This problem can usually be solved by making the inner subroutine anonymous, using the sub
{} syntax. When inner anonymous subs that reference variables in outer subroutines
are called or referenced, they are automatically rebound to the current values of such
variables.
warn "")
or you called it with no args and $_ was empty.
(F) An error peculiar to OS/2. PERLLIB_PREFIX should be of the form
|
or
|
with nonempty prefix1 and prefix2. If prefix1 is indeed a prefix of a
builtin library search path, prefix2 is substituted. The error may appear if components
are not found, or are too long. See "PERLLIB_PREFIX" in README.os2.
sh-shell
in. See "PERL_SH_DIR" in README.os2.
If you find what you think is a bug, you might check the headers of recently posted articles in the comp.lang.perl.misc newsgroup. 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 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 perl -V, will be sent off to <perlbug@perl.com>
to be analysed by the Perl porting team.
The Changes file for exhaustive details on what changed.
The INSTALL file for how to build Perl. This file has been significantly updated for 5.004, so even veteran users should look through it.
The README file for general stuff.
The Copying file for copyright information.
Constructed by Tom Christiansen, grabbing material with permission from innumerable contributors, with kibitzing by more than a few Perl porters.
Last update: Wed May 14 11:14:09 EDT 1997
|
|
© 2002-2004 Active-Venture.com Web Site Hosting Service |
|
|
|
|
| [ A computer lets you make more mistakes faster than any other invention in human history, with the possible exception of handguns and tequila. ] | |
|
|
|
Disclaimer: This
documentation is provided only for the benefits of our web hosting customers.
|