2

I know Perl recently got try / catch. What version of Perl though shipped with it?

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
  • 1
    [TryCatch changes](https://metacpan.org/dist/TryCatch/changes), [Object Oriented Exception Handling in Perl](https://www.perl.com/pub/2002/11/14/exception.html/) – Polar Bear Jun 16 '21 at 18:15
  • [How to properly use the try catch in perl that error.pm provides?](https://stackoverflow.com/questions/10342875/how-to-properly-use-the-try-catch-in-perl-that-error-pm-provides) – Polar Bear Jun 16 '21 at 18:36
  • 5
    @PolarBear this is self-answered, fyi. It's done. I just had to look it up and I'm trying to save people that in the future. **Note though this isn't about a module, Perl 5.34 has core try/catch, those links aren't really relevant** – Evan Carroll Jun 16 '21 at 18:43
  • The included links show that try/catch was on Perl programmers mind for a long time and there was many attempts to implement this feature. As of this moment my understanding is that this feature is not part Perl yet due it's maturity state. – Polar Bear Jun 16 '21 at 18:58
  • 4
    It is part of perl, it's just marked as experimental. It ships with Perl 5.34 and no modules are required outside of the standard coreutils. – Evan Carroll Jun 16 '21 at 19:06
  • For me _experimental_ is experimental -- not standard part of language construction. For example _experimental drug_ is not ready for mass public -- there can be serious side effects and probably some of them end with somebody's death. Experimental has some meaning of _Warning_ sing (be cautious when you use this feature). – Polar Bear Jun 16 '21 at 19:10
  • 3
    @PolarBear did you take the COVID vaccine? `signatures` have been "experimental" for over five years and they're used everywhere. I don't think that means what you think it means. It basically just means the implementation is subject to change and removal (not death). – Evan Carroll Jun 16 '21 at 20:16
  • Key words in your reply *subject to change and removal* -- when I wrote death the meaning was _death of the patient_ not death of _the drug_. *Subject to change* has hidden meaning _do not expect that code written today will produce same outcome with next release_ (try at your own risk no warranty included that code will behave same in future). – Polar Bear Jun 16 '21 at 20:30
  • 2
    @PolarBear likewise, you could say that about any major semvar version for all software. In Perl 5, all features are subject to change in Perl 7 (the next major version). And while it's unlikely that this feature is stable by Perl 7, it seems no more to the point than to just simply say you're less risk-averse than I am (and others): "all entities move and nothing remains still." I know enough about tomorrow to get there today, you can join me at your own leisure. – Evan Carroll Jun 16 '21 at 23:00
  • @EvanCarroll "Everyone else is doing it" isn't a very convincing argument. FYI signatures [are now stable](https://perldoc.perl.org/feature#The-'signatures'-feature). – Will Sheppard May 30 '22 at 12:09

2 Answers2

9

The mostly ignored perlexperiment page lists the features as they are added and (sometimes) later graduated out of the experimental category. You can also see when features were removed.

If you use the version at perldoc.perl.org, you are probably always reading the latest version of the stable docs (maybe off a few days right after a release), so you don't need to rely on your local docs. However, if it's not in your local docs, your Perl doesn't have it. :)

Similarly, the feature.pm docs shows the name of each feature, the name for its experimental warning when appropriate, and which version bundles each feature shows up in. That is, when you include use v5.x, which features are automatically included.

The experimental pragma (starting in v5.18) is useful in the same way, and perhaps a better summary of everything. Instead of these two lines:

use feature qw(try);
no warnings qw(experimental::try);

you have this one line:

use experimental qw(try);

That's even handier when you are turning off several feature warnings since you don't type out experimental:: before each of them:

use experimental qw(signatures try);
brian d foy
  • 129,424
  • 31
  • 207
  • 592
  • 1
    Note that `use experimental qw( try );` was accidentally left out of the documentation but works. – ikegami Jun 18 '21 at 21:24
6

Perl 5.36 added native support for finally.

Evan Carroll
  • 78,363
  • 46
  • 261
  • 468