develooper Front page | perl.perl5.porters | Postings from June 2021

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
From:
Ben Bullock
Date:
June 21, 2021 10:12
Subject:
Re: RFC 0004 - defer {} syntax
Message ID:
CAN5Y6m968=mvtAXgPJ7H0NzBsXg03VCb9cGEoc6umTioC0jEEA@mail.gmail.com
On Mon, 21 Jun 2021 at 11:08, Tom Molesworth <tom@binary.com> wrote:

> If you want something to execute in the parent scope, that can be done by
> putting the defer above the if() statement. How would the following be
> implemented with your suggested change in behaviour?
>
> if(condition) {
>  open my $fh, '>', 'output' or die;
>  defer { $fh->close and send_email_from_file('output') }
>  ... arbitrary code which may include next/return/die/goto ...
> }
> open my $fh, '>', 'output' or die;
>

I concede that you would be better off with the current implementation
rather than my suggestion if that is what you want to do with defer.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About