PERL5004DELTA(1)
π PERL5004DELTA π
okay bestie, gather round, because this is the perl5004delta page from the Perl Programmers Reference Guide and it's literally the glow-up diary of perl 5.004. it's giving "before and after" but for a programming language. no cap.
β¨ NAME β¨
perl5004delta β what's new for perl5.004 π
π¦ DESCRIPTION π¦
so this doc spills ALL the tea on what changed between the 5.003 release (you know it, the one documented in Programming Perl, second edition β yes, the Camel Book πͺ) and this one. bestie, it's a lot. hydrate first.
πΈ Supported Environments πΈ
Perl5.004 builds out of the box on Unix, Plan 9, LynxOS, VMS, OS/2, QNX, AmigaOS, and Windows NT. Perl runs on Windows 95 as well, but it cannot be built there, for lack of a reasonable command interpreter. (windows 95 said "not my problem" and honestly? valid of it π)
π Core Changes π
most importantly: SO many bugs got fixed, including several security problems. see the Changes file in the distribution for the deets. it's the receipts folder fr fr.
π List assignment to %ENV works π
%ENV = () and %ENV = @list now work as expected β except on VMS, where it generates a fatal error. (vms stays being the group chat member who leaves you on read π)
π Change to "Can't locate Foo.pm in @INC" error π
the error Can't locate Foo.pm in @INC now lists the contents of @INC for easier debugging. bestie the error message is finally helping instead of just vibing mysteriously β¨
π Compilation option: Binary compatibility with 5.003 π
there's a new Configure question that asks if you want to maintain binary compatibility with Perl 5.003. if you choose binary compatibility, you do not have to recompile your extensions β but you might get 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. periodt.
π $PERL5OPT environment variable π
you may now put Perl options in the $PERL5OPT environment variable. unless Perl is running with taint checks, it will interpret this variable as if its contents had appeared on a #!perl line at the beginning of your script β except that hyphens are optional. PERL5OPT may only be used to set the following switches: -[DIMUdmw]. that's the whole guest list, don't try to sneak anyone else in π
π Limitations on -M, -m, and -T options π
the -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. (iconic behavior, honestly β use is the main character here π)
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. π«
π More precise warnings π
if you removed the -w option from your Perl 5.003 scripts because it made Perl too verbose, we recommend that you try putting it back when you upgrade to Perl 5.004. each new perl version tends to remove some undesirable warnings, while adding new warnings that may catch bugs in your scripts. so like... the warnings got a makeover and they're actually serving now π
π Deprecated: Inherited "AUTOLOAD" for non-methods π
before Perl 5.004, 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' AUTOLOADs. 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. copy that, paste that, thank me later π«Ά
π Previously deprecated %OVERLOAD is no longer usable π
using %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 overload for more details. it's giving "we still use it but you can't, bestie" π
π 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 @_).
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). glow-down for $a[2] honestly π
π Group vector changeable with $) π
the $) 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). symmetry slay β¨
π Fixed parsing of $$<digit>, &$<digit>, etc. π
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. rip to the workaround, you served π«‘
π Fixed localization of $<digit>, $&, etc. π
Perl versions before 5.004 did not always properly localize the regex-related special variables. Perl 5.004 does localize them, as the documentation has always said it should. this may result in $1, $2, etc. no longer being set where existing programs use them. heads up bestie, your regex vars might be acting different now π
π No resetting of $. on implicit close π
the documentation for Perl 5.0 has always stated that $. 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 docs were right the whole time, we were just lying π
π "wantarray" may return undef π
the wantarray operator returns true if a subroutine is expected to return a list, and false otherwise. in Perl 5.004, wantarray can also return the undefined value if a subroutine's return value will not be used at all, which allows subroutines to avoid a time-consuming calculation of a return value if it isn't going to be used. efficiency queen π
π "eval EXPR" determines value of EXPR in scalar context π
Perl (version 5) used to determine the value of EXPR inconsistently, sometimes incorrectly using the surrounding context for the determination. now, the value of EXPR (before being parsed by eval) is always determined in a scalar context. once parsed, it is executed as before, by providing the context that the scope surrounding the eval provided. this change makes the behavior Perl4 compatible, besides fixing bugs resulting from the inconsistent behavior. this program:
@a = qw(time now is time);
print eval @a;
print '|', scalar eval @a;
used to print something like timenowis881399109|4, but now (and in perl4) prints 4|4. character development fr fr π
π 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 -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. like yeah your script broke but also you almost got hacked so ππ
the new restrictions when tainting include:
- No glob() or <*> β these operators may spawn the C shell (
csh), which cannot be made safe. this restriction will be lifted in a future version of Perl when globbing is implemented without the use of an external program. - No spawning if tainted $CDPATH, $ENV, $BASH_ENV β these environment variables may alter the behavior of spawned programs (especially shells) in ways that subvert security. so now they are treated as dangerous, in the manner of
$IFSand$PATH. - No spawning if tainted $TERM doesn't look like a terminal name β some termcap libraries do unsafe things with
$TERM. however, it would be unnecessarily harsh to treat all$TERMvalues as unsafe, since only shell metacharacters can cause trouble in$TERM. so a tainted$TERMis considered to be safe if it contains only alphanumerics, underscores, dashes, and colons, and unsafe if it contains other characters (including whitespace).
π New Opcode module and revised Safe module π
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. new modules just dropped π₯
π 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. multiple interpreters, no leaks, we love to see it π«Ά
π 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, *GLOB{FILEHANDLE} is now just a backward-compatible synonym for *GLOB{IO}. cute lil rebrand β¨
π Internal change: PerlIO abstraction interface π
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.
π New and changed syntax π
$coderef->(PARAMS)β 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). code refs are finally getting the respect they deserve π
(more parts coming bestie, don't go anywhere π)
okay so this new syntax is literally following the same pattern as $hashref->{FOO} and $aryref->[$foo]: you can now write &$subref($foo) as $subref->($foo). and bestie, all these arrow terms can be chained together, so &{$table->{FOO}}($bar) can now be written as $table->{FOO}->($bar). slay. π
β¨ New and changed builtin constants β¨
__PACKAGE__β this gives you the current package name at compile time, or the undefined value if there's no current package (like when you have apackage;directive). and just like__FILE__and__LINE__,__PACKAGE__does not interpolate into strings. periodt. π
πΈ New and changed builtin variables πΈ
$^Eβ extended error message on some platforms. (also known as$EXTENDED_OS_ERRORif youuse English). β¨$^Hβ the current set of syntax checks enabled byuse strict. see the docs forstrictfor more deets. not actually new, just newly documented. and because it's meant for internal use by Perl core components, there's nouse Englishlong name for this variable. π$^Mβ so by default, running out of memory is not trappable. but if compiled for this, Perl may use the contents of$^Mas an emergency pool afterdie()ing with this message. suppose your Perl was compiled with-DPERL_EMERGENCY_SBRKand used Perl's malloc. then
$^M = 'a' x (1<<16);
would allocate a 64K buffer for use in an emergency. see the INSTALL file for info on how to enable this option. and as a disincentive to casual use of this advanced feature, there's no use English long name for this variable. π«Ά
as a disincentive to casual use of this advanced feature, there's no use English long name for this variable. (so don't be messy with it, bestie) π
π₯ New and changed builtin functions π₯
delete on slices
this now works. (like delete @ENV{'PATH', 'MANPATH'}) slay. β¨
flock
is now supported on more platforms, prefers fcntl to lockf when emulating, and always flushes before (un)locking. π
printf and sprintf
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's now possible to know which conversions and flags will work, and what they'll 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 with0, hex with0xhβ interpret integer as C typeshortorunsigned shortVβ 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 in perlfunc for a complete list of conversion and flags. π
keys as an lvalue
as an lvalue, keys lets you 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
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() in Control Structures
you can now use my() (with or without the parentheses) in the control expressions of control structures like:
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 usemy()on global punctuation variables such as$_and the like. π
pack() and unpack()
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.) π§
sysseek()
the new 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's the only reliable way to seek before using sysread() or syswrite(). its return value is the new position, or the undefined value on failure. β
use VERSION
if the first argument to use is a number, it's 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.) π
use Module VERSION LIST
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's faster and can be used with modules that don't use the Exporter. it's the recommended method for new code. π
prototype(FUNCTION)
returns the prototype of a function as a string (or 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.) π
srand
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. π²
$_ as Default
functions documented in the Camel to default to $_ now in fact do, and all those that do are so documented in perlfunc. πͺ
"m//gc" does not reset search position on failure
the 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 ?*+{}
the 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. πβ‘οΈβ¨
nested "sub{}" closures work now
prior to the 5.004 release, nested anonymous functions didn't work right. they do now. β¨
formats work right on changing lexicals
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:
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
.
π New builtin methods π
the UNIVERSAL package automatically contains the following methods that are inherited by all other classes:
isa(CLASS)
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:
use UNIVERSAL qw(isa);
if(isa($ref, 'ARRAY')) {
...
}
can(METHOD)
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( [NEED] ) π
VERSION hands you back the version number of the class (package). And if the NEED argument is there, it checks that the current version β the one defined by the $VERSION variable in the given package β is not less than NEED; it will die if that's not the case. This method is normally called as a class method, and bestie, it gets called automatically by the VERSION form of use. π
use A 1.2 qw(some imported subs);
# implies:
A->VERSION(1.2);
NOTE:cangoes straight to Perl's internal code for method lookup, andisauses a very similar method plus a caching strategy. This may cause strange effects if the Perl code dynamically changes@ISAin any package. π
You can also add other methods to the UNIVERSAL class via Perl or XS code. And you do not need to use UNIVERSAL to make these methods available to your program β that's only necessary if you wish to have isa available as a plain subroutine in the current package. π«Ά
π TIEHANDLE now supported π
Peep perltie for the other kinds of tie()s, bestie.
TIEHANDLE classname, LIST β this is the constructor for the class, meaning it's expected to return an object of some sort. That reference can be used to hold some internal information.
sub TIEHANDLE {
print "<shout>\n";
my $i;
return bless \$i, shift;
}
PRINT this, LIST β this method fires every single 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++;
return print join( $, => map {uc} @_), $\;
}
PRINTF this, LIST β fires every time the tied handle is printed to with the printf() function. Beyond its self reference it also expects the format and list that were passed to the printf function.
sub PRINTF {
shift;
my $fmt = shift;
print sprintf($fmt, @_)."\n";
}
READ this LIST β called when the handle is read from via the read or sysread functions.
sub READ {
$r = shift;
my($buf,$len,$offset) = @_;
print "READ called, \$buf=$buf, \$len=$len, \$offset=$offset";
}
READLINE this β 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"
}
GETC this β called when the getc function is called.
sub GETC { print "Don't GETC, Get Perl"; return "a"; }
DESTROY this β just like with the other types of ties, this method gets called when the tied handle is about to be destroyed. It's useful for debugging and possibly for cleaning up.
sub DESTROY {
print "</shout>\n";
}
π§ Malloc enhancements π§
If perl got compiled with the malloc that ships with the perl distribution β aka if perl -V:d_mymalloc is 'define' β then you can print memory statistics at runtime by running Perl like this:
env PERL_DEBUG_MSTATS=2 perl your_script_here
The value 2 means to print statistics after compilation and on exit; with a value of 1, the statistics are printed only on exit. (And if you want the statistics at some arbitrary moment, 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().)
-DPERL_EMERGENCY_SBRKβ if this macro is defined, running out of memory doesn't have to be a fatal error: a memory pool can be allocated by assigning to the special variable$^M. See"$^M".-DPACK_MALLOCβ Perl memory allocation is by bucket with sizes close to powers of two. Because of that, malloc overhead may be big, especially for data of size exactly a power of two. IfPACK_MALLOCis 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 that are powers of two (and those show up 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).
-DTWO_POT_OPTIMIZEβ similarly toPACK_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 the system for a 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.
β¨ Miscellaneous efficiency enhancements β¨
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. Iconic behaviour, honestly. π₯
π Support for More Operating Systems π
Support for the following operating systems is new in Perl 5.004.
πͺ Win32
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 ExtUtils::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.
πΈ Plan 9
See README.plan9 in the perl distribution.
π¦ QNX
See README.qnx in the perl distribution.
πΈ AmigaOS
See README.amigaos in the perl distribution.
π§ Pragmata π§
Six new pragmatic modules exist:
use autouse MODULE => qw(sub1 sub2 sub3)β defersrequire MODULEuntil someone calls one of the specified subroutines (which must be exported byMODULE). This pragma should be used with caution, and only when necessary.use blibuse blib 'dir'β looks for MakeMaker-like'blib'directory structure starting in dir (or the current directory) and working back up to five levels of parent directories.
Intended for use on the command line with the -M option as a way of testing arbitrary scripts against an uninstalled version of a package.
use constant NAME => VALUEβ provides a convenient interface for creating compile-time constants. See "Constant Functions" in perlsub.use localeβ 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.
use opsβ disable unsafe opcodes, or any named opcodes, when compiling Perl code.use vmsishβ enable VMS-specific language features. Currently, there are three VMS-specific features available:'status', which makes$?andsystemreturn genuine VMS status values instead of emulating POSIX;'exit', which makesexittake a genuine VMS status value instead of assuming thatexit 1is an error; and'time', which makes all times relative to the local time zone, in the VMS tradition.
π§© Modules π§©
Required Updates
okay so here's the tea π« β Perl 5.004 plays nice with almost every module that works with Perl 5.003, but bestie, there are a few exceptions and you gotta know about them:
Module Required Version for Perl 5.004
------ -------------------------------
Filter Filter-1.12
LWP libwww-perl-5.08
Tk Tk400.202 (-w makes noise)
Also β and this is the part nobody warns you about π β the majordomo mailing list program, version 1.94.1, straight up does not work with Perl 5.004 (nor with perl 4), because it executes an invalid regular expression. Not a vibe. That bug is fixed in majordomo version 1.94.2, so go get that one. π
Installation directories
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 lived. Periodt. β¨
Why do you care? Because this change is intended to let administrators 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. It's giving responsible adult behaviour, honestly. π«Ά
Module information summary
Brand new modules, bestie!! π And they're arranged by topic rather than strictly alphabetically, which is honestly so much easier to read. Slay.
Web / CGI corner πΈοΈ
CGI.pmβ web server interface (that's "Common Gateway Interface" for the uninitiated)CGI/Apache.pmβ support for Apache's Perl moduleCGI/Carp.pmβ log server errors with helpful contextCGI/Fast.pmβ support for FastCGI (persistent server process)CGI/Push.pmβ support for server pushCGI/Switch.pmβ simple interface for multiple server types
CPAN corner π¦
CPANβ interface to Comprehensive Perl Archive NetworkCPAN::FirstTimeβ utility for creating CPAN configuration fileCPAN::Noxβ runs CPAN while avoiding compiled extensions
IO corner π§
IO.pmβ top-level interface toIO::*classesIO/File.pmβIO::Fileextension Perl moduleIO/Handle.pmβIO::Handleextension Perl moduleIO/Pipe.pmβIO::Pipeextension Perl moduleIO/Seekable.pmβIO::Seekableextension Perl moduleIO/Select.pmβIO::Selectextension Perl moduleIO/Socket.pmβIO::Socketextension Perl module
Opcode π
Opcode.pmβ disable named opcodes when compiling Perl code
ExtUtils corner π§°
ExtUtils/Embed.pmβ utilities for embedding Perl in C programsExtUtils/testlib.pmβ fixes up@INCto use just-built extension
FindBin π
FindBin.pmβ find path of currently executing program
The "by-name interface" squad π·οΈ (these are lowkey iconic)
Class/Struct.pmβ declare struct-like datatypes as Perl classesFile/stat.pmβ by-name interface to Perl's builtinstatNet/hostent.pmβ by-name interface to Perl's builtingethost*Net/netent.pmβ by-name interface to Perl's builtingetnet*Net/protoent.pmβ by-name interface to Perl's builtingetproto*Net/servent.pmβ by-name interface to Perl's builtingetserv*Time/gmtime.pmβ by-name interface to Perl's builtingmtimeTime/localtime.pmβ by-name interface to Perl's builtinlocaltimeTime/tm.pmβ internal object forTime::{gm,local}timeUser/grent.pmβ by-name interface to Perl's builtingetgr*User/pwent.pmβ by-name interface to Perl's builtingetpw*
Tie π
Tie/RefHash.pmβ base class for tied hashes with references as keys
The mothership π
UNIVERSAL.pmβ base class for ALL classes
Fcntl
New constants in the existing Fcntl modules are now supported β provided that your operating system happens to support them, which is the little asterisk on this whole situation π:
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(). Not me telling you to read the OS docs, but like... read the OS docs. π
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 β cute of her honestly). However, for historical reasons, these constants are not exported unless they are explicitly requested with the ":flock" tag (e.g. use Fcntl ':flock'). So don't come crying when they don't show up unprompted, bestie. π
IO
The IO module gives you a simple mechanism to load all the IO modules at one go. Currently this includes:
IO::Handle
IO::Seekable
IO::File
IO::Pipe
IO::Socket
For more information on any of these modules, please see its respective documentation. π
Math::Complex
The Math::Complex module has been totally rewritten, and now supports more operations. It ate, fr fr. These are overloaded:
+ - * / ** <=> 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
Math::Trig
This new module provides a simpler interface to parts of Math::Complex for those who need trigonometric functions only for real numbers. If you've ever been like "why am I importing complex-number machinery for a tan" β this is the module for you, bestie. π¦
DB_File
There have been quite a few changes made to DB_File. Here are a few of the highlights:
- Fixed a handful of bugs. π
- By public demand, added support for the standard hash function
exists(). - Made it compatible with Berkeley DB 1.86.
- Made negative subscripts work with the
RECNOinterface. - Changed the default flags from
O_RDWRtoO_CREAT|O_RDWRand the default mode from0640to0666. π - Made
DB_Fileautomatically import theopen()constants (O_RDWR,O_CREATetc.) fromFcntl, if available. - Updated documentation.
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. π
Net::Ping
Major rewrite β support added for both udp echo and real icmp pings. She's versatile now. π
Object-oriented overrides for builtin operators
Many of the Perl builtins returning lists now have object-oriented overrides. These are:
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);
which is so much nicer than whatever you were doing before, no cap. πβ¨
π οΈ Utility Changes π οΈ
pod2html
Sends converted HTML to standard output
The pod2html utility included with Perl 5.004 is entirely new. By default, it sends the converted HTML to its standard output, instead of writing it to a file like Perl 5.003's pod2html did. Use the --outfile=FILENAME option to write to a file. So if you were relying on the old file-writing behaviour, that's on you to update, bestie. π
xsubpp
"void" XSUBs now default to returning nothing
Okay so 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. π Yeah. That kind of bug. Rude.
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 *". Fix your types, queen. π
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 *". Detective work, honestly. π΅οΈ
π» C Language API Changes π»
"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 ofgv_fetchmethodtoperl_call_svis 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). So if it works once and then explodes β that's why. π
"perl_eval_pv"
A new function handy for eval'ing strings of Perl code inside C code. This function returns the value from the eval statement, which can be used instead of fetching globals from the symbol table. See perlguts, perlembed and perlcall for details and examples. Very "best of both worlds" of her. π«Ά
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 β no need to panic. π§
The additions to the API allow passing keys as 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. Efficiency? We love her. β
π Documentation Changes π
Many of the base and library pods were updated. These new pods are included in section 1:
perldeltaβ this document. (Hi. You're reading her. π)perlfaqβ frequently asked questions.perllocaleβ locale support (internationalization and localization).perltootβ tutorial on Perl OO programming.perlapioβ Perl internal IO abstraction interface.perlmodlibβ Perl module library and recommended practice for module creation. Extracted from perlmod (which is much smaller as a result). She lost weight, good for her. πperldebugβ although not new, this has been massively updated.perlsecβ although not new, this has been massively updated.
π¨ New Diagnostics π¨
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 β yes, really, that's the scale we're working with π):
(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). π½
"my" variable %s masks earlier declaration in same scope
(W) bestie π you just redeclared a lexical variable in the same scope, which means you've literally cut off all access to the first one. Nine times out of ten this is just a typo. But plot twist β the earlier variable isn't gone-gone; it hangs around until the end of the scope, or until every closure that refers to it gets destroyed. So it's giving haunted house, not deleted.
%s argument is not a HASH element or slice
(F) whatever you handed to delete() has to be a hash element, like this:
$foo{$bar}
$ref->[12]->{"susie"}
or a hash slice, like this:
@foo{$bar, $baz, $xyzzy}
@{$ref->[12]}{"susie", "queue"}
no in-between, no vibes, just those. β¨
Allocation too large: %lx
(X) you cannot allocate more than 64K on an MS-DOS machine. that's the whole ceiling. π«
Allocation too large
(F) you cannot allocate more than 2^31+"small amount" bytes. that's the line, bestie.
Applying %s to %s will act on scalar(%s)
(W) the pattern match (//), substitution (s///), and transliteration (tr///) operators work on scalar values, okay? So if you aim one at an array or a hash, Perl converts that array or hash into a scalar value first β the length of an array, or the population info of a hash β and then operates on that. Which is almost definitely not what you were going for. π Peep "grep" in perlfunc and "map" in perlfunc for the alternatives you actually want.
Attempt to free nonexistent shared string
(P) Perl keeps a reference-counted internal table of strings to make hash keys and other strings cheaper to store and access. This one means somebody tried to decrement the reference count of a string that is no longer findable in that table. It's giving ghost of a string past. π»
Attempt to use reference as lvalue in substr
(W) you passed a reference as the first argument to substr() while using it as an lvalue, which is honestly pretty strange of you. Maybe you forgot to dereference it first? See "substr" in perlfunc. π
Bareword "%s" refers to nonexistent package
(W) you used a qualified bareword shaped like "Foo::", but the compiler hadn't seen any other use of that namespace before that point. Maybe you need to predeclare a package? π€
Can't redefine active sort subroutine %s
(F) Perl optimizes how it handles sort subroutines internally and keeps pointers into them. You tried to redefine one of those sort subroutines while it was currently active, and that is not allowed, periodt. If you truly need to do this, write sort { &func } @x instead of sort func @x. π₯
Can't use bareword ("%s") as %s ref while "strict refs" in use
(F) "strict refs" only allows hard references. Symbolic references are disallowed, no exceptions. See perlref.
Cannot resolve method %s' overloading %s' in package `%s'
(P) this is an internal error that pops up when Perl tries to resolve overloading specified by a method name β as opposed to a subroutine reference. Not your fault, bestie.
Constant subroutine %s redefined
(S) you redefined a subroutine that had previously been eligible for inlining. See "Constant Functions" in perlsub for the commentary and the workarounds. πΈ
Constant subroutine %s undefined
(S) you undefined a subroutine that had previously been eligible for inlining. See "Constant Functions" in perlsub for commentary and workarounds.
Copy method did not return a reference
(F) the method which overloads "=" is buggy. That's it, that's the tea. See "Copy Constructor" in overload. π
Died
(F) you passed die() an empty string (the equivalent of die "") or you called it with no args and both $@ and $_ were empty. So it died of emptiness, lowkey tragic. π
Exiting pseudo-block via %s
(W) you're exiting a rather special block construct β think a sort block or a subroutine β by unconventional means, like a goto, or a loop control statement. See "sort" in perlfunc.
Identifier too long
(F) Perl caps identifiers (names for variables, functions, etc.) at 252 characters for simple names, and somewhat more for compound names (like $A::B). You blew past Perl's limits. Future versions of Perl are likely to eliminate these arbitrary limitations, so likeβ¦ eventually. β¨
Illegal character %s (carriage return)
(F) a carriage return character was found in the input. This is an error and not a warning because carriage return characters can break multi-line strings, including here documents (e.g., print <<EOF;). So it's not being dramatic, it's being protective. π«Ά
Illegal switch in PERL5OPT: %s
(X) the PERL5OPT environment variable may only be used to set the following switches: -[DIMUdmw]. That's the guest list, and your switch isn't on it. π
Integer overflow in hex number
(S) the literal hex number you specified is too big for your architecture. On a 32-bit architecture the largest hex literal is 0xFFFFFFFF.
Integer overflow in octal number
(S) the literal octal number you specified is too big for your architecture. On a 32-bit architecture the largest octal literal is 037777777777.
internal error: glob failed
(P) something went wrong with the external program(s) used for "glob" and <*.c>. This may mean 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. π
Invalid conversion in %s: "%s"
(W) Perl does not understand the given format conversion. See "sprintf" in perlfunc.
Invalid type in pack: '%s'
(F) the given character is not a valid pack type. See "pack" in perlfunc.
Invalid type in unpack: '%s'
(F) the given character is not a valid unpack type. See "unpack" in perlfunc.
Name "%s::%s" used only once: possible typo
(W) typographical errors often show up as unique variable names. So if you had a good reason for having a unique name, just mention it again somehow to suppress the message (the "use vars" pragma is provided for just this purpose). π
Null picture in formline
(F) the first argument to formline must be a valid format picture specification. It was found to be empty, which probably means you supplied it an uninitialized value. See perlform.
Offset outside string
(F) you tried to do a read/write/send/recv operation with an offset pointing outside the buffer. Honestly? Difficult to imagine. The sole exception to this is that sysread()ing past the buffer will extend the buffer and zero pad the new area. π¦
Out of memory!
(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. π§
Out of memory during request for %s
(F) the 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. π
panic: frexp
(P) the library function frexp() failed, making printf("%f") impossible.
Possible attempt to put comments in qw() list
(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:
@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
);
Possible attempt to separate words with 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:
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 !;
Scalar value @%s{%s} better written as $%s{%s}
(W) you've used a hash slice (indicated by @) to select a single element of a hash. Generally it's better to ask for a scalar value (indicated by $). The difference is that $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. π
Stub found while resolving method %s' overloading %s' in %s
(P) overloading resolution over the @ISA tree may be broken by importing stubs. Stubs should never be implicitly created, but explicit calls to "can" may break this. π
Too late for "-T" option
(X) the #! line (or local equivalent) in a Perl script contains the -T option, but Perl was not invoked with -T in its argument list. This is an error because, by the time Perl discovers a -T in a script, it's too late to properly taint everything from the environment. So Perl gives up. π«
untie attempted while %d inner references still exist
(W) a copy of the object returned from "tie" (or "tied") was still valid when "untie" was called. Rude, honestly.
Unrecognized character %s
(F) the Perl parser has no idea what to do with the specified character in your Perl script (or eval). Perhaps you tried to run a compressed script, a binary program, or a directory as a Perl program. We've all been there. π
Unsupported function fork
(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. β
Use of "$$<digit>" to mean "${$}<digit>" is deprecatedβ (D) okay so before Perl 5.004, any type marker followed by"$"and a digit got misinterpreted. Like"$$0"was incorrectly taken to mean"${$}0"instead of"${$0}". This bug is (mostly) fixed in Perl 5.004.
But bestie, the devs couldn't fix it 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; it just throws this message as a warning. And in Perl 5.005, this special treatment will cease. periodt π
Value of %s can be "0"; test with defined()β (W) In a conditional expression, you used<HANDLE>,<*>(glob),each(), orreaddir()as a boolean value. The thing is, each of these constructs can return a value of"0"; that would make the conditional expression false, which is probably not what you intended. So when you use these constructs in conditional expressions, test their values with the"defined"operator. no cap.Variable "%s" may be unavailableβ (W) So there's an inner (nested) anonymous subroutine 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:
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. π
Variable "%s" will not stay sharedβ (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. iconic fix tbh.
Warning: something's wrongβ (W) You passedwarn()an empty string (the equivalent of"warn """) or you called it with no args and$_was empty. mood.Ill-formed logical name |%s| in prime_env_iterβ (W) A warning peculiar to VMS. A logical name was encountered when preparing to iterate over%ENVwhich 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. yikes.Got an error from DosAllocMemβ (P) An error peculiar to OS/2. Most probably you're using an obsolete version of Perl, and this should not happen anyway. fr fr.Malformed PERLLIB_PREFIXβ (F) An error peculiar to OS/2.PERLLIB_PREFIXshould be of the form
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. π
PERL_SH_DIR too longβ (F) An error peculiar to OS/2.PERL_SH_DIRis the directory to find the"sh"-shell in. See"PERL_SH_DIR"inREADME.os2.Process terminated by SIG%sβ (W) This is a standard message issued by OS/2 applications, while *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"in perlipc. See also"Process terminated by SIGTERM/SIGINT"inREADME.os2. π
π BUGS π
ok so if you find what you think is a bug, maybe check the headers of recently posted articles in the comp.lang.perl.misc newsgroup. There may also be info 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. ty bestie π«Ά
π SEE ALSO π
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. slay.
π HISTORY π
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. iconic.
and that's the tea from perl v5.42.3, dated 2026-08-03 β this was PERL5004DELTA(1), bye bestie πβ¨
π¦ where this page comes from
- fedora 43: perl-doc 5.42.3-524.fc43 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND Unicode-3.0 AND LicenseRef-Fedora-UltraPermissive
- fedora 44: perl-doc 5.42.3-525.fc44 Β· (GPL-1.0-or-later OR Artistic-1.0-Perl) AND Unicode-3.0 AND LicenseRef-Fedora-UltraPermissive
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms