AUTOLOAD
for non-methods
$)
%ENV = ()
and %ENV = @list
now work as expected (except on
VMS where it generates a fatal error).
-M
and -m options are no longer allowed on the #!
line of a script. If a script needs a module, it should invoke it with the
use pragma.
The -T option is also forbidden on the #!
line of a script, unless it was present on the Perl command line. Due to
the way #!
works, this usually means that -T must be in the first argument. Thus:
#!/usr/bin/perl -T -w
will probably work for an executable script invoked as scriptname
, while:
#!/usr/bin/perl -w -T
will probably fail under the same conditions. (Non-Unix systems will
probably not follow this rule.) But perl scriptname
is guaranteed to fail, since then there is no chance of -T being found on the command line before it is found on the #!
line.
AUTOLOAD
for non-methods
AUTOLOAD
functions were looked up as methods (using the @ISA
hierarchy), even when the function to be autoloaded was called as a plain
function (e.g. Foo::bar()
), not a method (e.g. Foo->bar()
or $obj->bar()
).
Perl 5.005 will use method lookup only for methods' AUTOLOAD
s. However, there is a significant base of existing code that may be using
the old behavior. So, as an interim step, Perl 5.004 issues an optional
warning when a non-method uses an inherited AUTOLOAD
.
The simple rule is: Inheritance will not work when autoloading non-methods.
The simple fix for old code is: In any module that used to depend on
inheriting AUTOLOAD
for non-methods from a base class named
BaseClass
, execute *AUTOLOAD = \&BaseClass::AUTOLOAD
during startup.
%OVERLOAD
to define overloading was deprecated in 5.003.
Overloading is now defined using the overload pragma.
%OVERLOAD
is still used internally but should not be used by
Perl scripts. See
the overload manpage for more details.
@_
).
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 and 5.001 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).
$)
$)
special variable has always (well, in Perl 5, at least) reflected not only
the current effective group, but also the group list as returned by the getgroups()
C function (if there is one). However, until this
release, there has not been a way to call the
setgroups()
C function from Perl.
In Perl 5.004, assigning to $)
is exactly symmetrical with examining it: The first number in its string
value is used as the effective gid; if there are any numbers after the
first one, they are passed to the
setgroups()
C function (if there is one).
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.
$.
is not
reset when an already-open file handle is reopened with no intervening call
to close. Due to a bug, perl versions 5.000 through 5.003
did reset $.
under that circumstance; Perl 5.004 does not.
The new restrictions when tainting include:
$IFS
and
$PATH.
$TERM
values as unsafe, since only shell metacharacters can cause trouble in
$TERM. So a tainted $TERM
is considered to be safe if it contains only alphanumerics, underscores, dashes, and colons, and unsafe if it contains other characters (including whitespace).
In harmony with this change, *GLOB{FILEHANDLE}
is now just a backward-compatible synonym for *GLOB{IO}
.
This new syntax follows the pattern of $hashref->{FOO}
and
$aryref->[$foo]
: You may now write &$subref($foo)
as
$subref->($foo)
. All of these arrow terms may be chained; thus, &{$table->{FOO}}($bar)
may now be written
$table->{FOO}->($bar)
.
__FILE__
and __LINE__
, __PACKAGE__ does not interpolate into strings.
$EXTENDED_OS_ERROR
if you 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.
$^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
$^M = 'a' x (1<<16);
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'}
)
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:
%i a synonym for %d %p a pointer (the address of the Perl value, in hexadecimal) %n special: *stores* the number of characters output so far into the next variable in the parameter list
The new flags that go between the %
and the conversion are:
# prefix octal with "0", hex with "0x" h interpret integer as C type "short" or "unsigned short" V interpret integer as Perl's standard integer type
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 sprintf for a complete list of conversion and flags.
keys %hash = 200;
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).
my()
(with or without the parentheses) in the
control expressions of control structures such as:
while (defined(my $line = <>)) { $line = lc $line; } continue { print $line; }
if ((my $answer = <STDIN>) =~ /^y(es)?$/i) { user_agrees(); } elsif ($answer =~ /^n(o)?$/i) { user_disagrees(); } else { chomp $answer; die "`$answer' is neither `yes' nor `no'"; }
Also, you can declare a foreach loop control variable as lexical by preceding it with the word ``my''. For example, in:
foreach my $i (1, 2, 3) { some_function(); }
$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.
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.)
sysseek()
operator is a variant of seek()
that sets and gets the file's system read/write position, using the
lseek(2)
system call. It is the only reliable way to seek
before using sysread()
or syswrite().
Its return
value is the new position, or the undefined value on failure.
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.)
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.
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.
$_
now in fact
do, and all those that do are so documented in the perlfunc manpage.
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 the perlop manpage
and the perlre manpage.
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.
foreach
loop), formats now work properly. For example, this silently failed before
(printed only zeros), but is fine now:
my $i; foreach $i ( 1 .. 10 ) { write; } format = my i is @# $i .
However, it still fails (without a warning) if the foreach is within a subroutine:
my $i; sub foo { foreach $i ( 1 .. 10 ) { write; } } foo; format = my i is @# $i .
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:
use UNIVERSAL qw(isa);
if(isa($ref, 'ARRAY')) { ... }
METHOD
, if it does then a reference to the sub is returned; if it does not then
undef is returned.
use A 1.2 qw(some imported subs); # implies: A->VERSION(1.2);
@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.
tie()s.
sub TIEHANDLE { print "<shout>\n"; my $i; return bless \$i, shift; }
sub PRINT { $r = shift; $$r++; return print join( $, => map {uc} @_), $\; }
sub PRINTF { shift; my $fmt = shift; print sprintf($fmt, @_)."\n"; }
sub READ { $r = shift; my($buf,$len,$offset) = @_; print "READ called, \$buf=$buf, \$len=$len, \$offset=$offset"; }
sub READLINE { $r = shift; return "PRINT called $$r times\n" }
sub GETC { print "Don't GETC, Get Perl"; return "a"; }
sub DESTROY { print "</shout>\n"; }
perl -V:d_mymalloc
is 'define') then 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 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.
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).
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.
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.
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 for more details on this port, and how to obtain the Cygwin32 toolkit.
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.
Intended for use on command line with -M option as a way of testing arbitrary scripts against an uninstalled version of a package.
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 formating 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 the perllocale manpage 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.
Module Required Version for Perl 5.004 ------ ------------------------------- Filter Filter-1.12 LWP libwww-perl-5.08 Tk Tk400.202 (-w makes noise)
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.
CGI.pm Web server interface ("Common Gateway Interface") CGI/Apache.pm Support for Apache's Perl module CGI/Carp.pm Log server errors with helpful context CGI/Fast.pm Support for FastCGI (persistent server process) CGI/Push.pm Support for server push CGI/Switch.pm Simple interface for multiple server types
CPAN Interface to Comprehensive Perl Archive Network CPAN::FirstTime Utility for creating CPAN configuration file CPAN::Nox Runs CPAN while avoiding compiled extensions
IO.pm Top-level interface to IO::* classes IO/File.pm IO::File extension Perl module IO/Handle.pm IO::Handle extension Perl module IO/Pipe.pm IO::Pipe extension Perl module IO/Seekable.pm IO::Seekable extension Perl module IO/Select.pm IO::Select extension Perl module IO/Socket.pm IO::Socket extension Perl module
Opcode.pm Disable named opcodes when compiling Perl code
ExtUtils/Embed.pm Utilities for embedding Perl in C programs ExtUtils/testlib.pm Fixes up @INC to use just-built extension
FindBin.pm Find path of currently executing program
Class/Struct.pm Declare struct-like datatypes as Perl classes File/stat.pm By-name interface to Perl's builtin stat Net/hostent.pm By-name interface to Perl's builtin gethost* Net/netent.pm By-name interface to Perl's builtin getnet* Net/protoent.pm By-name interface to Perl's builtin getproto* Net/servent.pm By-name interface to Perl's builtin getserv* Time/gmtime.pm By-name interface to Perl's builtin gmtime Time/localtime.pm By-name interface to Perl's builtin localtime Time/tm.pm Internal object for Time::{gm,local}time User/grent.pm By-name interface to Perl's builtin getgr* User/pwent.pm By-name interface to Perl's builtin getpw*
Tie/RefHash.pm Base class for tied hashes with references as keys
UNIVERSAL.pm Base class for *ALL* classes
F_GETOWN F_SETOWN 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()
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():
LOCK_SH LOCK_EX LOCK_NB LOCK_UN
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'
).
IO::Handle IO::Seekable IO::File IO::Pipe IO::Socket
For more information on any of these modules, please see its respective documentation.
+ - * / ** <=> neg ~ abs sqrt exp log sin cos atan2 "" (stringify)
And these functions are now exported:
pi i Re Im arg log10 logn ln cbrt root tan csc sec cot asin acos atan acsc asec acot sinh cosh tanh csch sech coth asinh acosh atanh acsch asech acoth cplx cplxe
exists().
open()
constants
(O_RDWR,
O_CREAT etc.) from Fcntl, if available.
File::stat Net::hostent Net::netent Net::protoent Net::servent Time::gmtime Time::localtime User::grent User::pwent
For example, you can now say
use File::stat; use User::pwent; $his = (stat($filename)->st_uid == pwent($whoever)->pw_uid);
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 *.
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).
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 the perlguts manpage for details.
(W) A warning (optional). (D) A deprecation (optional). (S) A severe warning (mandatory). (F) A fatal error (trappable). (P) An internal error you should never see (trappable). (X) A very fatal error (nontrappable). (A) An alien error message (not generated by Perl).
delete()
must be
either a hash element, such as
$foo{$bar} $ref->[12]->{"susie"}
or a hash slice, such as
@foo{$bar, $baz, $xyzzy} @{$ref->[12]}{"susie", "queue"}
substr()
used as an lvalue, which is pretty strange. Perhaps
you forgot to dereference it first. See substr.
sort { &func } @x
instead of sort func @x
.
die()
an empty string (the
equivalent of 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;
).
program(s)
used for 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).
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.
malloc()
function returned 0, indicating there was insufficient remaining memory (or virtual memory) to satisfy the request. However, the request was judged large enough (compile-time default is
64K), so a possibility to shut down by trapping this error is granted.
frexp()
failed,
making printf(``%f'')
impossible.
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 exclamation marks parentheses shown here; braces are
also frequently used.)
You probably wrote something like this:
@list = qw( a # a comment b # another comment );
when you should have written this:
@list = qw( a b );
If you really want comments, build your list the old-fashioned way, with quotes and commas:
@list = ( 'a', # a comment 'b', # another comment );
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:
qw! a, b, c !;
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:
qw! a b c !;
$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.
@ISA
tree
may be broken by importing stubs. Stubs should never be implicitely
created, but explicit calls to can
may break this.
tied
) was still valid when untie was called.
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.
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.
sub outermost { my $a; sub middle { sub { $a } } }
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.
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()
an empty string
(the equivalent of warn "") or you called it with no args and $_
was empty.
%ENV
which violates the syntactic rules governing logical names. Since it cannot be translated normally, it is skipped, and will not appear in
%ENV. This may be a benign occurrence, as some software packages might directly modify logical name tables and introduce nonstandard names, or it may indicate that a logical name table has been corrupted.
prefix1;prefix2
or
prefix1 prefix2
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.
*nix
applications die in silence. It is considered a feature of the
OS/2 port. One can easily disable this by appropriate sighandlers, see
Signals. See also ``Process terminated by
SIGTERM/SIGINT'' in README.os2.
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 <[email protected]> to be analysed by the Perl porting team.
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.
Last update: Wed May 14 11:14:09 EDT 1997