You are viewing the version of this documentation from Perl 5.39.2. This is a development version of Perl.

CONTENTS

NAME

perl5380delta - what is new for perl v5.38.0

DESCRIPTION

This document describes differences between the 5.36.0 release and the 5.38.0 release.

Core Enhancements

New class Feature

A new experimental syntax is now available for defining object classes, where per-instance data is stored in "field" variables that behave like lexicals.

use feature 'class';

class Point
{
    field $x;
    field $y;

    method zero { $x = $y = 0; }
}

This is described in more detail in perlclass. Notes on the internals of its implementation and other related details can be found in perlclassguts.

This remains a new and experimental feature, and is very much still under development. It will be the subject of much further addition, refinement and alteration in future releases. As it is experimental, it yields warnings in the experimental::class category. These can be silenced by a no warnings statement.

use feature 'class';
no warnings 'experimental::class';

Unicode 15.0 is supported

See https://www.unicode.org/versions/Unicode15.0.0/ for details.

Deprecation warnings now have specific subcategories

All deprecation warnings now have their own specific deprecation category which can be disabled individually. You can see a list of all deprecated features in perldeprecation, and in warnings. The following list is from warnings:

+- deprecated ----+
|                 |
|                 +- deprecated::apostrophe_as_package_separator
|                 |
|                 +- deprecated::delimiter_will_be_paired
|                 |
|                 +- deprecated::dot_in_inc
|                 |
|                 +- deprecated::goto_construct
|                 |
|                 +- deprecated::smartmatch
|                 |
|                 +- deprecated::unicode_property_name
|                 |
|                 +- deprecated::version_downgrade

It is still possible to disable all deprecation warnings in a single statement with

no warnings 'deprecated';

but now is possible to have a finer grained control. As has historically been the case these warnings are automatically enabled with

use warnings;

%{^HOOK} API introduced

For various reasons it can be difficult to create subroutine wrappers for some of perl's keywords. Any keyword which has an undefined prototype simply cannot be wrapped with a subroutine, and some keywords which perl permits to be wrapped are in practice very tricky to wrap. For example require is tricky to wrap, it is possible but doing so changes the stack depth, and the standard methods of exporting assume that they will be exporting to a package at certain stack depth up the stack, and the wrapper will thus change where functions are exported to unless implemented with a great deal of care. This can be very awkward to deal with.

Accordingly we have introduced a new hash called %{^HOOK} which is intended to facilitate such cases. When a keyword supports any kind of special hook then the hook will live in this new hash. Hooks in this hash will be named after the function they are called by, followed by two underbars and then the phase they are executed in, currently either before or after the keyword is executed.

In this initial release we support two hooks require__before and require__after. These are provided to make it easier to perform tasks before and after a require statement.

See perlvar for more details.

PERL_RAND_SEED

Added a new environment variable PERL_RAND_SEED which can be used to cause a perl program which uses rand without using srand() explicitly or which uses srand() with no arguments to be repeatable. See perlrun. This feature can be disabled at compile time by passing

-Accflags=-DNO_PERL_RAND_SEED

to Configure during the build process.

Defined-or and logical-or assignment default expressions in signatures

The default expression for a subroutine signature parameter can now be assigned using the //= or ||= operators, to apply the defaults whenever the caller provided an undefined or false value (respectively), rather than simply when the parameter is missing entirely. For more detail see the documentation in perlsub.

@INC Hook Enhancements and $INC and INCDIR

The internals for @INC hooks have been hardened to handle various edge cases and should no longer segfault or throw assert failures when hooks modify @INC during a require operation. As part of this we now ensure that any given hook is executed at most once during a require call, and that any duplicate directories do not trigger additional directory probes.

To provide developers more control over dynamic module lookup, a new hook method INCDIR is now supported. An object supporting this method may be injected into the @INC array, and when it is encountered in the module search process it will be executed, just like how INC hooks are executed, and its return value used as a list of directories to search for the module. Returning an empty list acts as a no-op. Note that since any references returned by this hook will be stringified and used as strings, you may not return a hook to be executed later via this API.

When an @INC hook (either INC or INCDIR) is called during require, the $INC variable will be localized to be the value of the index of @INC that the hook came from. If the hook wishes to override what the "next" index in @INC should be it may update $INC to be one less than the desired index (undef is equivalent to -1). This allows an @INC hook to completely rewrite the @INC array and have perl restart its directory probes from the beginning of @INC.

Blessed CODE references in @INC that do not support the INC or INCDIR methods will no longer trigger an exception, and instead will be treated the same as unblessed coderefs are, and executed as though they were an INC hook.

Forbidden control flow out of defer or finally now detected at compile-time

It is forbidden to attempt to leave a defer or finally block by means of control flow such as return or goto. Previous versions of perl could only detect this when actually attempted at runtime.

This version of perl adds compile-time detection for many cases that can be statically determined. This may mean that code which compiled successfully on a previous version of perl is now reported as a compile-time error with this one. This only happens in cases where it would have been an error to actually execute the code anyway; the error simply happens at an earlier time.

Optimistic Eval in Patterns

The use of (?{ ... }) and (??{ ... }) in a pattern disables various optimisations globally in that pattern. This may or may not be desired by the programmer. This release adds the (*{ ... }) equivalent. The only difference is that it does not and will never disable any optimisations in the regex engine. This may make it more unstable in the sense that it may be called more or less times in the future, however the number of times it executes will truly match how the regex engine functions. For example, certain types of optimisation are disabled when (?{ ... }) is included in a pattern, so that patterns which are O(N) in normal use become O(N*N) with a (?{ ... }) pattern in them. Switching to (*{ ... }) means the pattern will stay O(N).

REG_INF has been raised from 65,536 to 2,147,483,647

Many regex quantifiers used to be limited to U16_MAX in the past, but are now limited to I32_MAX, thus it is now possible to write /(?:word){1000000}/ for example. Note that doing so may cause the regex engine to run longer and use more memory.

New API functions optimize_optree and finalize_optree

There are two new API functions for operating on optree fragments, ensuring you can invoke the required parts of the optree-generation process that might otherwise not get invoked (e.g. when creating a custom LOGOP). To get access to these functions, you first need to set a #define to opt-in to using these functions.

#define PERL_USE_VOLATILE_API

These functions are closely tied to the internals of how the interpreter works, and could be altered or removed at any time if other internal changes make that necessary.

Some gotos are now permitted in defer and finally blocks

Perl version 5.36.0 added defer blocks and permitted the finally keyword to also add similar behaviour to try/catch syntax. These did not permit any goto expression within the body, as it could have caused control flow to jump out of the block. Now, some goto expressions are allowed, if they have a constant target label, and that label is found within the block.

use feature 'defer';

defer {
  goto LABEL;
  print "This does not execute\n";
  LABEL: print "This does\n";
}

New regexp variable ${^LAST_SUCCESSFUL_PATTERN}

This allows access to the last succesful pattern that matched in the current scope. Many aspects of the regex engine refer to the "last successful pattern". The empty pattern reuses it, and all of the magic regex vars relate to it. This allows access to its pattern. The following code

if (m/foo/ || m/bar/) {
    s//PQR/;
}

can be rewritten as follows

if (m/foo/ || m/bar/) {
    s/${^LAST_SUCCESSFUL_PATTERN}/PQR/;
}

and it will do the exactly same thing.

Locale category LC_NAME now supported on participating platforms

On platforms that have the GNU extension LC_NAME category, you may now use it as the category parameter to "setlocale" in POSIX to set and query its locale.

Incompatible Changes

readline() no longer clears the stream error and eof flags

readline(), also spelled <>, would clear the handle's error and eof flags after an error occurred on the stream.

In nearly all cases this clear is no longer done, so the error and eof flags now properly reflect the status of the stream after readline().

Since the error flag is no longer cleared calling close() on the stream may fail and if the stream was not explicitly closed, the implicit close of the stream may produce a warning.

This has resulted in two main types of problems in downstream CPAN modules, and these may also occur in your code:

The only case where error and eof flags continue to cleared on error is when reading from the child process for glob() in miniperl. This allows it to correctly report errors from the child process on close(). This is unlikely to be an issue during normal perl development.

[GH #20060]

INIT blocks no longer run after an exit() in BEGIN

INIT blocks will no longer run after an exit() performed inside of a BEGIN. This means that the combination of the -v option and the -c option no longer executes a compile check as well as showing the perl version. The -v option executes an exit(0) after printing the version information inside of a BEGIN block, and the -c check is implemented by using INIT hooks, resulting in the -v option taking precedence.

[GH #1537] [GH #20181]

Syntax errors no longer produce "phantom error messages"

Generally perl will continue parsing the source code even after encountering a compile error. In many cases this is helpful, for instance with misspelled variable names it is helpful to show as many examples of the error as possible. But in the case of syntax errors continuing often produces bizarre error messages and may even cause segmentation faults during the compile process. In this release the compiler will halt at the first syntax error encountered. This means that any code expecting to see the specific error messages we used to produce will be broken. The error that is emitted will be one of the diagnostics that used to be produced, but in some cases some messages that used to be produced will no longer be displayed.

See "Changes to Existing Diagnostics" for more details.

utf8::upgrade()

Starting in this release, if the input string is undef, it remains undef. Previously it would be changed into a defined, zero-length string.

Changes to "thread-safe" locales

Perl 5.28 introduced "thread-safe" locales on systems that supported them, namely modern Windows, and systems supporting POSIX 2008 locale operations. These systems accomplish this by having per-thread locales, while continuing to support the older global locale operations for code that doesn't take the steps necessary to use the newer per-thread ones.

It turns out that some POSIX 2008 platforms have or have had buggy implementations, which forced perl to not use them. The ${^SAFE_LOCALES} scalar variable contains 0 or 1 to indicate whether or not the current platform is considered by perl to have a working thread-safe implementation. Some implementations have been fixed already, but FreeBSD and Cygwin have been newly discovered to be sufficiently buggy that the thread-safe operations are no longer used by perl, starting in this release. Hence, ${^SAFE_LOCALES} is now 0 for them. Older versions of perl can be configured to avoid these buggy implementations by adding the Configure option -DNO_POSIX_2008_LOCALE.

And v5.38 fixes a bug in all previous perls that led to locales not being fully thread-safe. The first thread that finishes caused the main thread (named thread0) to revert to the global locale in effect at startup, discarding whatever the thread's locale had been previously set to. If any other thread had switched to the global locale by calling switch_to_global_locale() in XS code, those threads would all share the global locale, and thread0 would not be thread-safe.

Deprecations

Use of ' as a package name separator is deprecated

Using ' as package separator in a variable named in a double-quoted string has warned since 5.28. It is now deprecated in both string interpolation and non-interpolated contexts, and will be removed in Perl 5.42.

Switch and Smart Match operator

The "switch" feature and the smartmatch operator, ~~, were introduced in v5.10. Their behavior was significantly changed in v5.10.1. When the "experiment" system was added in v5.18.0, switch and smartmatch were retroactively declared experimental. Over the years, proposals to fix or supplement the features have come and gone.

In v5.38.0, we are declaring the experiment a failure. Some future system may take the conceptual place of smartmatch, but it has not yet been designed or built.

These features will be entirely removed from perl in v5.42.0.

Performance Enhancements

Modules and Pragmata

Updated Modules and Pragmata

Documentation

New Documentation

perlclass

Describes the new class feature.

perlclassguts

Describes the internals of the new class feature.

Changes to Existing Documentation

We have attempted to update the documentation to reflect the changes listed in this document. If you find any we have missed, open an issue at https://github.com/Perl/perl5/issues.

Additionally, the following selected changes have been made:

perlapi

perldeprecation

perlintern

perlexperiment

perlfunc

perlhacktips

perlop

perlvar

Diagnostics

The following additions or changes have been made to diagnostic output, including warnings and fatal error messages. For the complete list of diagnostic messages, see perldiag.

New Diagnostics

New Errors

New Warnings

Changes to Existing Diagnostics

Configuration and Compilation

Testing

Tests were added and changed to reflect the other additions and changes in this release. Furthermore, these significant changes were made:

Platform Support

Discontinued Platforms

Ultrix

Support code for DEC Ultrix has been removed. Ultrix was the native Unix-like operating system for various Digital Equipment Corporation machines. Its final release was in 1995.

Platform-Specific Notes

DragonflyBSD

Skip tests to workaround an apparent bug in setproctitle(). [GH #19894]

FreeBSD

FreeBSD no longer uses thread-safe locale operations, to avoid a bug in FreeBSD

Replace the first part of archname with uname -p [GH #19791]

Solaris

Avoid some compiler and compilation issues on NetBSD/Solaris from regexec.c and regcomp.c.

Synology

Update Synology Readme for DSM 7.

Windows

Fix win32 memory alignment needed for gcc-12 from vmem.h.

utimes() on Win32 would print a message to stderr if it failed to convert a supplied time_t to a FILETIME. [GH #19668]

In some cases, timestamps returned by stat() and lstat() failed to take daylight saving time into account. [GH #20018] [GH #20061]

stat() now works on AF_UNIX socket files. [GH #20204]

readlink() now returns the PrintName from a symbolic link reparse point instead of the SubstituteName, which should make it better match the name the link was created with. [GH #20271]

lstat() on Windows now returns the length of the link target as the size of the file, as it does on POSIX systems. [GH #20476]

symlink() on Windows now replaces any / in the target with \, since Windows does not recognise / in symbolic links. The reverse translation is not done by readlink(). [GH #20506]

symlink() where the target was an absolute path to a directory was incorrectly created as a file symbolic link. [GH #20533]

POSIX::dup2 no longer creates broken sockets. [GH #20920]

Closing a busy pipe could cause Perl to hang. [GH #19963]

Internal Changes

Selected Bug Fixes

Acknowledgements

Perl 5.38.0 represents approximately 12 months of development since Perl 5.36.0 and contains approximately 290,000 lines of changes across 1,500 files from 100 authors.

Excluding auto-generated files, documentation and release tools, there were approximately 190,000 lines of changes to 970 .pm, .t, .c and .h files.

Perl continues to flourish into its fourth decade thanks to a vibrant community of users and developers. The following people are known to have contributed the improvements that became Perl 5.38.0:

Alex, Alexander Nikolov, Alex Davies, Andreas König, Andrew Fresh, Andrew Ruthven, Andy Lester, Aristotle Pagaltzis, Arne Johannessen, A. Sinan Unur, Bartosz Jarzyna, Bart Van Assche, Benjamin Smith, Bram, Branislav Zahradník, Brian Greenfield, Bruce Gray, Chad Granum, Chris 'BinGOs' Williams, chromatic, Clemens Wasser, Craig A. Berry, Dagfinn Ilmari Mannsåker, Dan Book, danielnachun, Dan Jacobson, Dan Kogai, David Cantrell, David Golden, David Mitchell, E. Choroba, Ed J, Ed Sabol, Elvin Aslanov, Eric Herman, Felipe Gasper, Ferenc Erki, Firas Khalil Khana, Florian Weimer, Graham Knop, Håkon Hægland, Harald Jörg, H.Merijn Brand, Hugo van der Sanden, James E Keenan, James Raspass, jkahrman, Joe McMahon, Johan Vromans, Jonathan Stowe, Jon Gentle, Karen Etheridge, Karl Williamson, Kenichi Ishigaki, Kenneth Ölwing, Kurt Fitzner, Leon Timmermans, Li Linjie, Loren Merritt, Lukas Mai, Marcel Telka, Mark Jason Dominus, Mark Shelor, Matthew Horsfall, Matthew O. Persico, Mattia Barbon, Max Maischein, Mohammad S Anwar, Nathan Mills, Neil Bowers, Nicholas Clark, Nicolas Mendoza, Nicolas R, Paul Evans, Paul Marquess, Peter John Acklam, Peter Levine, Philippe Bruhat (BooK), Reini Urban, Renee Baecker, Ricardo Signes, Richard Leach, Russ Allbery, Scott Baker, Sevan Janiyan, Sidney Markowitz, Sisyphus, Steve Hay, TAKAI Kousuke, Todd Rinaldo, Tomasz Konojacki, Tom Stellard, Tony Cook, Tsuyoshi Watanabe, Unicode Consortium, vsfos, Yves Orton, Zakariyya Mughal, Zefram, 小鸡.

The list above is almost certainly incomplete as it is automatically generated from version control history. In particular, it does not include the names of the (very much appreciated) contributors who reported issues to the Perl bug tracker.

Many of the changes included in this version originated in the CPAN modules included in Perl's core. We're grateful to the entire CPAN community for helping Perl to flourish.

For a more complete list of all of Perl's historical contributors, please see the AUTHORS file in the Perl source distribution.

Reporting Bugs

If you find what you think is a bug, you might check the perl bug database at https://github.com/Perl/perl5/issues. There may also be information at http://www.perl.org/, the Perl Home Page.

If you believe you have an unreported bug, please open an issue at https://github.com/Perl/perl5/issues. Be sure to trim your bug down to a tiny but sufficient test case.

If the bug you are reporting has security implications which make it inappropriate to send to a public issue tracker, then see "SECURITY VULNERABILITY CONTACT INFORMATION" in perlsec for details of how to report the issue.

Give Thanks

If you wish to thank the Perl 5 Porters for the work we had done in Perl 5, you can do so by running the perlthanks program:

perlthanks

This will send an email to the Perl 5 Porters list with your show of thanks.

SEE ALSO

The Changes file for an explanation of how to view exhaustive details on what changed.

The INSTALL file for how to build Perl.

The README file for general stuff.

The Artistic and Copying files for copyright information.