![]() |
|
Support for CHECK blocksIn addition to POSIX character class syntax [: :] supportedFor example to match alphabetic characters use /[[:alpha:]]/. See perlre for details. Better pseudo-random number generatorIn 5.005_0x and earlier, perl's rand() function used the C library rand(3) function. As of 5.005_52, Configure tests for drand48(), random(), and rand() (in that order) and picks the first one it finds. These changes should result in better random numbers from rand(). Improved
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
now correctly prints "3|a", instead of "2|a".
Small changes in the hashing algorithm have been implemented in order to improve the distribution of lower order bits in the hashed value. This is expected to yield better performance on keys that are repeated sequences.
The new format type 'Z' is useful for packing and unpacking null-terminated strings. See perlfunc/"pack".
The new format type modifier '!' is useful for packing and unpacking native shorts, ints, and longs. See perlfunc/"pack".
The template character '/' can be used to specify a counted string type to be packed or unpacked. See perlfunc/"pack".
The '#' character in a template introduces a comment up to end of the line. This facilitates documentation of pack() templates.
In previous versions of Perl, you couldn't cache objects so as to allow them to be deleted if the last reference from outside the cache is deleted. The reference in the cache would hold a reference count on the object and the objects would never be destroyed.
Another familiar problem is with circular references. When an object references itself, its reference count would never go down to zero, and it would not get destroyed until the program is about to exit.
Weak references solve this by allowing you to "weaken" any reference, that is, make it not count towards the reference count. When the last non-weak reference to an object is deleted, the object is destroyed and all the weak references to the object are automatically undef-ed.
To use this feature, you need the Devel::WeakRef package from CPAN, which contains additional documentation.
|
Binary numbers are now supported as literals, in s?printf formats, and oct():
|
Subroutines can now return modifiable lvalues. See perlsub/"Lvalue subroutines".
|
Perl now allows the arrow to be omitted in many constructs involving subroutine calls
through references. For example, $foo[10]->('foo') may now be written $foo[10]('foo').
This is rather similar to how the arrow may be omitted from $foo[10]->{'foo'}.
Note however, that the arrow is still required for foo(10)->('bar').
Constructs such as ($a ||= 2) += 1 are now allowed.
The exists() builtin now works on subroutine names. A subroutine is considered to exist if it has been declared (even if implicitly). See perlfunc/exists for examples.
The exists() and delete() builtins now work on simple arrays as well. The behavior is similar to that on hash elements.
exists() can be used to check whether an array element has been initialized. This avoids autovivifying array elements that don't exist. If the array is tied, the EXISTS() method in the corresponding tied package will be invoked.
delete() may be used to remove an element from the array and return it. The array element at that position returns to its uninitialized state, so that testing for the same element with exists() will return false. If the element happens to be the one at the end, the size of the array also shrinks up to the highest element that tests true for exists(), or 0 if none such is found. If the array is tied, the DELETE() method in the corresponding tied package will be invoked.
See perlfunc/exists and perlfunc/delete for examples.
Dereferencing some types of reference values in a pseudo-hash, such as $ph->{foo}[1],
was accidentally disallowed. This has been corrected.
When applied to a pseudo-hash element, exists() now reports whether the specified value exists, not merely if the key is valid.
delete() now works on pseudo-hashes. When given a pseudo-hash element or slice it deletes the values corresponding to the keys (but not the keys themselves). See perlref/"Pseudo-hashes: Using an array as a hash".
Pseudo-hash slices with constant keys are now optimized to array lookups at compile-time.
List assignments to pseudo-hash slices are now supported.
The fields pragma now provides ways to create pseudo-hashes, via fields::new()
and fields::phash(). See fields.
|
fork(), exec(), system(), qx//, and pipe open()s now flush buffers of all files opened for output when the operation was attempted. This mostly eliminates confusing buffering mishaps suffered by users unaware of how Perl internally handles I/O.
This is not supported on some platforms like Solaris where a suitably correct implementation of fflush(NULL) isn't available.
Constructs such as open(<FH>) and close(<FH>) are
compile time errors. Attempting to read from filehandles that were opened only for writing
will now produce warnings (just as writing to read-only filehandles does).
open(NEW, "<&OLD") now attempts to discard any data that was
previously read and buffered in OLD before duping the handle. On platforms where
doing this is allowed, the next read operation on NEW will return the same data
as the corresponding operation on OLD. Formerly, it would have returned the data
from the start of the following disk block instead.
eof() would return true if no attempt to read from <> had
yet been made. eof() has been changed to have a little magic of its own, it now
opens the <> files.
binmode() now accepts a second argument that specifies a discipline for the handle in question. The two pseudo-disciplines ":raw" and ":crlf" are currently supported on DOS-derivative platforms. See perlfunc/"binmode" and open.
-T
filetest recognizes UTF-8 encoded files as "text"The algorithm used for the -T filetest has been enhanced to correctly identify
UTF-8 content as "text".
On Unix and similar platforms, system(), qx() and open(FOO, "cmd |") etc., are implemented via fork() and exec(). When the underlying exec() fails, earlier versions did not report the error properly, since the exec() happened to be in a different process.
The child process now communicates with the parent about the error in launching the external command, which allows these constructs to return with their usual error value and set $!.
Line numbers are no longer suppressed (under most likely circumstances) during the global destruction phase.
Diagnostics emitted from code running in threads other than the main thread are now accompanied by the thread ID.
Embedded null characters in diagnostics now actually show up. They used to truncate the message in prior versions.
$foo::a and $foo::b are now exempt from "possible typo" warnings only if sort()
is encountered in package foo.
Unrecognized alphabetic escapes encountered when parsing quote constructs now generate a warning, since they may take on new semantics in later versions of Perl.
Many diagnostics now report the internal operation in which the warning was provoked, like so:
|
Diagnostics that occur within eval may also report the file and line number where the eval is located, in addition to the eval sequence number and the line number within the evaluated text itself. For example:
|
Diagnostic output now goes to whichever file the STDERR handle is pointing at,
instead of always going to the underlying C runtime library's stderr.
On systems that support a close-on-exec flag on filehandles, the flag is now set for any handles created by pipe(), socketpair(), socket(), and accept(), if that is warranted by the value of $^F that may be in effect. Earlier versions neglected to set the flag for handles created with these operators. See perlfunc/pipe, perlfunc/socketpair, perlfunc/socket, perlfunc/accept, and perlvar/$^F.
The length argument of syswrite() has become optional.
Expressions such as:
|
used to be accidentally allowed in earlier versions, and produced unpredictable behaviour. Some produced ancillary warnings when used in this way; others silently did the wrong thing.
The parenthesized forms of most unary operators that expect a single argument now ensure that they are not called with more than one argument, making the cases shown above syntax errors. The usual behaviour of:
|
remains unchanged. See perlop.
The bit operators (& | ^ ~ << >>) now operate on the full native integral
width (the exact size of which is available in $Config{ivsize}). For example, if your platform
is either natively 64-bit or if Perl has been configured to use 64-bit integers, these
operations apply to 8 bytes (as opposed to 4 bytes on 32-bit platforms). For portability, be
sure to mask off the excess bits in the result of unary ~, e.g., ~$x &
0xffffffff.
More potentially unsafe operations taint their results for improved security.
The passwd and shell fields returned by the getpwent(), getpwnam(),
and getpwuid() are now tainted, because the user can affect their own encrypted password and
login shell.
The variable modified by shmread(), and messages returned by msgrcv() (and its object-oriented interface IPC::SysV::Msg::rcv) are also tainted, because other untrusted processes can modify messages and shared memory segments for their own nefarious purposes.
Bareword prototypes have been rationalized to enable them to be used to override builtins
that accept barewords and interpret them in a special way, such as require or do.
Arguments prototyped as * will now be visible within the subroutine as either
a simple scalar or as a reference to a typeglob. See perlsub/Prototypes.
require and do
may be overriddenrequire and do 'file' operations may be overridden locally by
importing subroutines of the same name into the current package (or globally by importing them
into the CORE::GLOBAL:: namespace). Overriding require will also affect use,
provided the override is visible at compile-time. See perlsub/"Overriding
Built-in Functions".
Formerly, $^X was synonymous with ${"\cX"}, but $^XY was a syntax error. Now
variable names that begin with a control character may be arbitrarily long. However, for
compatibility reasons, these variables must be written with explicit braces, as ${^XY}
for example. ${^XYZ} is synonymous with ${"\cXYZ"}. Variable names with
more than one control character, such as ${^XY^Z}, are illegal.
The old syntax has not changed. As before, `^X' may be either a literal control-X character
or the two-character sequence `caret' plus `X'. When braces are omitted, the variable name
stops after the control character. Thus "$^XYZ" continues to be
synonymous with $^X . "YZ" as before.
As before, lexical variables may not have names beginning with control characters. As
before, variables whose names begin with a control character are always forced to be in
package `main'. All such variables are reserved for future extensions, except those that begin
with ^_, which may be used by user programs and are guaranteed not to acquire
special meaning in any future version of Perl.
-c
switch$^C has a boolean value that reflects whether perl is being run in
compile-only mode (i.e. via the -c switch). Since BEGIN blocks are executed under
such conditions, this variable enables perl code to determine whether actions that make sense
only during normal running are warranted. See perlvar.
$^V contains the Perl version number as a string composed of characters whose
ordinals match the version numbers, i.e. v5.6.0. This may be used in string comparisons.
See Support for strings represented as a vector of ordinals for an example.
If Perl is built with the cpp macro PERL_Y2KWARN defined, it emits optional
warnings when concatenating the number 19 with another number.
This behavior must be specifically enabled when running Configure. See INSTALL and README.Y2K.
In double-quoted strings, arrays now interpolate, no matter what. The behavior in earlier versions of perl 5 was that arrays would interpolate into strings if the array had been mentioned before the string was compiled, and otherwise Perl would raise a fatal compile-time error. In versions 5.000 through 5.003, the error was
|
In versions 5.004_01 through 5.6.0, the error was
|
The idea here was to get people into the habit of writing "fred\@example.com"
when they wanted a literal @ sign, just as they have always written "Give
me back my \$5" when they wanted a literal $ sign.
Starting with 5.6.1, when Perl now sees an @ sign in a double-quoted string,
it always attempts to interpolate an array, regardless of whether or not the array has
been used or declared already. The fatal error has been downgraded to an optional warning:
|
This warns you that "fred@example.com" is going to turn into fred.com
if you don't backslash the @. See http://www.plover.com/~mjd/perl/at-error.html
for more details about the history here.
|
|
© 2002-2004 Active-Venture.com Web Site Hosting Service |
|
|
|
|
| [ Of course, the best way to get accurate information on Usenet is to post something wrong and wait for corrections. ] | |
|
|
|
Disclaimer: This
documentation is provided only for the benefits of our web hosting customers.
|