After 11 months of development published release of a new stable branch of the Perl programming language – 5.40. At preparation new release, about 160 thousand lines of code were changed (without documentation and automatically generated code – 110 thousand), changes affected 1,500 files, 75 developers took part in the development.
Branch 5.40 was released in accordance with the fixed development schedule approved eleven years ago, which implies the release of new stable branches once a year and corrective releases every three months. In about a month, it is planned to release the first corrective release of Perl 5.40.1, which will correct the most significant errors identified during the implementation of Perl 5.40.0. Along with the release of Perl 5.40, support for the 5.36 branch was discontinued, for which updates can be released in the future only if critical security problems are identified. On June 20, the development process of the experimental branch 5.41 will begin, on the basis of which a stable release of Perl 5.42 will be formed in May or June 2025, unless a decision is made to switch to numbering 7.x.
Key changes:
- Expanded features that appeared in the previous version experimental syntax to create classes. Added new keyword “__CLASS__“, which when called from methods, ADJUST blocks, or when initializing fields, returns the name of the current class, similar to how the __PACKAGE__ keyword returns the name of a package. Unlike the ref($self) expression, the __CLASS__ keyword can be used when initializing fields to access class methods before the class instance is created. For a base class, the value of __CLASS__ is identical to the value of __PACKAGE__, but will be different when creating subclasses.
use feature 'class'; class Example1 { field $f = __CLASS__->default_f; sub default_f { 10 } } - For fields defined within a class, the attribute “:reader“, used to automatically create a method that returns the value of a variable from a field in the current instance of the class. For example, specifying “:reader” after defining a field “field $s;” is equivalent to creating a method “method s() { return $s; }”. If necessary, you can specify a non-matching method name using a construction like “field $name :reader(get_name);”.
- Exception handling syntax declared stable try/catch, which can be used instead of non-obvious manipulations with “eval”. A “try” block contains a block containing the code to be executed, and a “catch” block contains code to handle any exception that might occur when the first block is executed. In “catch” a variable is defined that contains the data passed when an exception is thrown (for example, when an exception is triggered, the string specified as an argument will be passed to the “die” call). Jump statements are allowed inside “try” and “catch” blocks, including return, goto, next, last, and redo.
try { my $x = call_a_function(); $x < 100 or die "Too big"; send_output($x); } catch ($e) { warn "Unable to output a value; $e"; } print "Finished\n"; - The syntax “for my (VAR, VAR) (LIST)” and “foreach my (VAR, VAR) (LIST)” has been stabilized. applied for iterating over lists with simultaneous extraction of several values at once in one iteration of the loop. For example, you can now specify:
foreach my ($key, $value) (%hash) { ... } for my ($left, $right, $gripping) (@moties) { ... } - Module declared stable builtin, which includes always-available functions built into the interpreter. The module currently offers true, false, weaken, unweaken, is_weak, blessed, refaddr, reftype, ceil, floor, is_tainted, trim, and indexed functions.
- Added new experimental inf and nan built-ins available in the “builtin::” namespace (“builtin::inf” and “builtin::nan”). These functions can be used as constants that define infinity and non-numeric value.
- Added a new logical operator “^^” corresponding to the XOR operation and complementing the bitwise operator “^” (Perl provides three basic bitwise operators “&”, “|” and “^” corresponding to the AND, OR and XOR operations, but for logical Until now, the only operations available were AND (“&&”) and OR (“||”)). The Boolean expression “$x ^^ $y” will return TRUE when either “x” or “y” is TRUE, but not both.
- Support for simulation versions prior to 5.11 has been discontinued. Using the ” directiveuse version_number“, which disables additional features added to the interpreter after the specified version, with a version number less than 5.11 (for example, “use v5.8”) will now result in an error rather than a warning. Similarly, a warning has been added when used in the “use” version less than 5.39 (warnings will be replaced by a bug in the 5.44 release).
- It is allowed to use a space between the command line option “-M” and the module name, for example “perl -M Data::Dumper=Dumper -E 'say Dumper (1,2,3)'” (previously you had to write “perl -MData: :Dumper…”).
- The use of the “goto” statement to move from an outer scope to an inner scope has been deprecated. This feature will be discontinued in Perl 5.42.
- The main composition includes modules Term::Table And Test2::Suite, intended for creating unit tests. Updated versions of modules Archive::Tar, Compress::Raw::Bzip2, Compress::Raw::Zlib, Data::Dumper, DB_File, File::Compare, File::Find, Getopt::Long, Hash::Util , HTTP::Tiny, IO, Math::BigInt, PerlIO::encoding, Tie::File, Time::HiRes, etc.
- Added support for the Serenity OS operating system.
- Two vulnerabilities have been fixed:
- CVE-2023-47038 An out-of-bounds write occurred when handling invalid Unicode user-defined properties. An issue may result in a 1-byte buffer overflow when processing specially formatted regular expressions.
- CVE-2023-47039 – Possibility of executable file spoofing on the Windows platform due to a search for cmd.exe in paths using the PATH environment variable, in which the current working directory takes precedence over the system directory containing the cmd.exe executable.
Thanks for reading: