Re: 5.40 released
by marto (Cardinal) on Jun 10, 2024 at 09:06 UTC
|
| [reply] |
Re: 5.40 released (perl new feature References)
by eyepopslikeamosquito (Archbishop) on Jun 11, 2024 at 01:19 UTC
|
use feature 'try';
try {
do_a_thing();
}
catch ( $e ) {
warn "It failed - $e";
}
while perl v5.36 further added finally blocks to try/catch, also inspired by Syntax::Keyword::Try:
use feature 'try';
try {
do_a_thing();
}
catch( $e ) { ... }
finally {
cleanup();
}
While updating my try-catch sample program from perl v5.38.2 to v5.40.0, I noticed that while
try-catch feature is no longer experimental with perl v5.40 its use with a finally block still emitted a warning ...
presumably because try and catch were added in perl v5.34, while finally was not added until perl v5.36
... so I expect the finally block warning will finally disappear in perl v5.42. :-)
Perl Feature References Added Later
Recent Features:
- try catch finally (perldoc)
- Syntax::Keyword::Try on CPAN by Paul Evans - a try/catch/finally syntax for perl
- Feature::Compat::Try on CPAN by Paul Evans - make try/catch syntax available (if the new syntax is available this module simply enables the core feature equivalent to using it directly; on older versions of perl before such syntax is available, it is provided instead using Syntax::Keyword::Try)
- Try::Tiny on CPAN by Karen Etheridge - minimal try/catch with proper preservation of $@
- perlclass (perldoc) - class, field, method
- Feature::Compat::Class on CPAN by Paul Evans - make class syntax available (a work-in-progress, like the underlying perlclass feature)
- Object::Pad on CPAN by Paul Evans - a simple syntax for lexical field-based objects
- What's New in Perl v5.40? Mohammad Sajid Anwar on perl.com (Jun 2024) : 1) new __CLASS__ keyword; 2) :reader attribute for field variables; 3) a space is permitted in the -M command-line option; 4) new ^^ logical xor operator; 5) try/catch feature is no longer experimental; 6) for iterating over multiple values at a time is no longer experimental
- builtin (perldoc) - Perl pragma to import built-in utility functions (introduced in perl v5.36)
- use builtin ':5.40' bundles true false weaken unweaken is_weak blessed refaddr reftype ceil floor is_tainted trim indexed
- Note: The overall builtin mechanism, as well as every individual function it provides, are currently experimental
Older Features:
- autodie (perldoc) - new core pragma added to perl v5.10.1
Basic Feature References:
- say feature - perl 5.10
- state feature - perl 5.10
- switch feature - perl 5.10: deprecated, removed in perl 5.42
- unicode_strings feature - perl 5.12
- unicode_eval and evalbytes features - perl 5.16
- current_sub feature - perl 5.16
- fc feature - perl 5.16
- lexical_subs feature - perl 5.26
- array_base feature - removed in perl 5.30
- postderef and postderef_qq features - perl 5.30
- signatures feature - perl 5.36
- refaliasing feature - perl 5.22 (still experimental)
- declared_refs feature - perl 5.26 (still experimental)
- ... Re^2: Passing argument by reference (for a scalar) by ikegami gives an example using refaliasing/declared_refs and compares to Data::Alias
- bitwise feature - perl 5.28
- isa feature - perl 5.36
- indirect feature - perl 5.32
- multidimensional feature - perl 5.34
- bareword_filehandles feature - perl 5.34
- try feature - perl 5.34
- builtin pragma - perl 5.36
- defer feature - perl 5.36
- extra_paired_delimiters feature - perl 5.36
- finally added to try feature - perl 5.36
- module_true feature - perl 5.38
- class feature - perl 5.38
- perl v5.40 feature bundle : bitwise current_sub evalbytes fc isa module_true postderef_qq say signatures state try unicode_eval unicode_strings
Feature switch Removal:
See Also
| [reply] [d/l] [select] |
Re: 5.40 released
by choroba (Cardinal) on Jun 10, 2024 at 10:01 UTC
|
And Syntax::Construct trying to keep up! (Still waiting for Pause to index the latest release... Update: it's up!)
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
| [reply] [d/l] |
Re: 5.40 released
by ikegami (Patriarch) on Jun 13, 2024 at 03:53 UTC
|
| [reply] |
Re: 5.40 released
by cavac (Prior) on Jun 12, 2024 at 14:38 UTC
|
I'm one of those old-school people, so i followed ye olde https://cpan.org/src instructions as usual, e.g.
wget https://www.cpan.org/src/5.0/perl-5.40.0.tar.gz
tar -xzf perl-5.40.0.tar.gz
cd perl-5.40.0
./Configure -des -Dprefix=/home/cavac/bin/CavacPerl-5.40.0
make
make test
make install
And, as usual, everything works out fine on Xubuntu 22.04 LTS with the latest OS updates(*). And now i can FINALLY write cleaner code:
#!/usr/bin/env perl
use v5.40;
use strict; # <-- technically not required, but makes it clear to the
+reader we are using strict
use warnings; # <-- technically not required (i think), but makes it c
+lear to the reader we are using warnings
# <- no *EXPERIMENTAL* stuff here
for(my $i = 0; $i < 10; $i++) {
# Note to reader: Yes, could have used a trinary here, but those a
+re hard to read
# and therefore forbidden in my codebase
print "$i is ";
if(!iseven($i)) {
print "NOT ";
}
print "even\n";
}
sub iseven($val) {
if($val % 2 == 0) {
return true; # !!!!! A NATIVE BOOLEAN!!!!
}
return false; # The *other*, more pessimistic, native boolean ;-)
}
* Famous last words. Still installing all my codebases, but so far everything looks peachy.
| [reply] [d/l] [select] |
|
use v5.40;
use strict; use warnings;
my @some = ( 4, 5, 6 );
print $some[ true ], q[ ], $some[ false ];
... ?
💩Sadly, no ("5 4" are printed; tried on Perl Banjo).
Cross post: https://tech.lgbt/@parvXtl/112606032658432152
| [reply] [d/l] |
|
Why would you want it to issue a warning in that context? Seems consistent with
print $some[ 1 > 0 ], q[ ], $some[ 1 < 0 ];
| [reply] [d/l] |
|
|
|
for (0 .. 9) {
print "$_ is ";
print "NOT " if not iseven($_);
print "even\n";
}
Code should be optimized for efficient execution more than readability. Here Perl does both, since creating blocks is more expensive than postfix logic, especially inside loops. Peace
| [reply] [d/l] [select] |
|
He was simply showing some of the features of the 5.40.0 release, not trying to demonstrate some beautiful or optimized code, making such nitpicking seem pretty out of place and off topic.
| [reply] |
|
|
|
|
|
|
|
Implicit variables, e.g. $_, are banned from my project. If you use a variable, you have to name it. This makes it much clearer on first glance on what data you are working. And it makes it much easier to move around.
I should note that i'm paid to develop commercial software, meaning i always have some junior developers come and go. The goal with my code design is to make it easy to convert them from other languages. And i often have to convert code to (or from) Perl to other languages. "The most perlish way" is nearly always a bad idea, whereas a C-like for loop is available in most languages.
| [reply] |
|
|
|
|
|
|
|
|