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

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
Paul "LeoNerd" Evans
June 20, 2021 12:09
Re: RFC 0004 - defer {} syntax
Message ID:
On Sun, 20 Jun 2021 19:51:10 +0900
Ben Bullock <> wrote:

> I suggested this because I can't see how running a deferred block of
> code at the end of an "if" block would be useful in practice,

The clean "mental model" of how it operates.

  "defer {} runs its code when we hit the next nested }"

As opposed to

  "defer {} runs its code when we hit the next nested } that wasn't an
  if{} or elsif{} or unless{}, or maybe we'd consider adding do {} to
  that list since you can't next out of them and what about match/case
  blocks and ...."

`defer {}` runs at the same time that `my` variables go out of scope,
and `local` modifications get undone. This is by design to make it
simpler to learn and understand.

Paul "LeoNerd" Evans      |  |

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About