perl
view release on metacpan or search on metacpan
pod/perl5360delta.pod view on Meta::CPAN
stable on an ongoing basis. Other functions will be added to C<builtin> over
time.
For details, see L<builtin>, but here's a summary of builtin functions in
v5.36:
=over 4
=item builtin::trim
This function treats its argument as a string, returning the result of removing
all white space at its beginning and ending.
=item builtin::indexed
This function returns a list twice as big as its argument list, where each item
is preceded by its index within that list. This is primarily useful for using
the new C<foreach> syntax with multiple iterator variables to iterate over an
array or list, while also tracking the index of each item:
use builtin 'indexed';
foreach my ($index, $val) (indexed @array) {
...
}
=item builtin::true, builtin::false, builtin::is_bool
C<true> and C<false> return boolean true and false values. Perl is still perl,
and doesn't have strict typing of booleans, but these values will be known to
have been created as booleans. C<is_bool> will tell you whether a value was
known to have been created as a boolean.
=item builtin::weaken, builtin::unweaken, builtin::is_weak
These functions will, respectively: weaken a reference; strengthen a reference;
and return whether a reference is weak. (A weak reference is not counted for
garbage collection purposes. See L<perlref>.) These can take the place of
some similar routines in L<Scalar::Util>.
=item builtin::blessed, builtin::refaddr, builtin::reftype
These functions provide more data about references (or non-references,
actually!) and can take the place of similar routines found in L<Scalar::Util>.
=item builtin::ceil, builtin::floor
C<ceil> returns the smallest integer greater than or equal to its argument.
C<floor> returns the largest integer less than or equal to its argument. These
can take the place of similar routines found in L<POSIX>.
=back
=head2 C<defer> blocks (experimental)
This release adds support for C<defer> blocks, which are blocks of code
prefixed by the C<defer> modifier. They provide a section of code which runs
at a later time, during scope exit.
In brief, when a C<defer> block is reached at runtime, its body is set aside to
be run when the enclosing scope is exited. It is unlike a UNITCHECK (among
other reasons) in that if the block I<containing> the C<defer> block is exited
before the block is reached, it will not be run.
C<defer> blocks can be used to take the place of "scope guard" objects where an
object is passed a code block to be run by its destructor.
For more information, see L<perlsyn/"defer blocks">.
=head2 try/catch can now have a C<finally> block (experimental)
The experimental C<try>/C<catch> syntax has been extended to support an
optional third block introduced by the C<finally> keyword.
try {
attempt();
print "Success\n";
}
catch ($e) {
print "Failure\n";
}
finally {
print "This happens regardless\n";
}
This provides code which runs at the end of the C<try>/C<catch> construct,
even if aborted by an exception or control-flow keyword. They are similar
to C<defer> blocks.
For more information, see L<perlsyn/"Try Catch Exception Handling">.
=head2 non-ASCII delimiters for quote-like operators (experimental)
Perl traditionally has allowed just four pairs of string/pattern
delimiters: S<C<( )>> S<C<{ }>> S<C<[ ]>> and S<C<< < > >>>, all in the
ASCII range. Unicode has hundreds more possibilities, and using this
feature enables many of them. When enabled, you can say S<C<qr« »>> for
example, or S<C<use utf8; qðstringð>>. See L<feature/The
'extra_paired_delimiters' feature> for details.
=head2 @_ is now experimental within signatured subs
Even though subroutine signatures are now stable, use of the legacy arguments
array (C<@_>) with a subroutine that has a signature I<remains> experimental,
with its own warning category. Silencing the C<experimental::signatures>
warning category is not sufficient to dismiss this. The new warning is emitted
with the category name C<experimental::args_array_with_signatures>.
Any subroutine that has a signature and tries to make use of the defaults
argument array or an element thereof (C<@_> or C<$_[INDEX]>), either
explicitly or implicitly (such as C<shift> or C<pop> with no argument) will
provoke a warning at compile-time:
use v5.36;
sub f ($x, $y = 123) {
say "The first argument is $_[0]";
}
Z<>
( run in 1.633 second using v1.01-cache-2.11-cpan-5b529ec07f3 )