Skip to content

Instantly share code, notes, and snippets.

@lucs
Created March 26, 2023 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucs/5a9b5c5ccfc5c7be59403e7d033ce5b4 to your computer and use it in GitHub Desktop.
Save lucs/5a9b5c5ccfc5c7be59403e7d033ce5b4 to your computer and use it in GitHub Desktop.
Control a LEAVE block's execution
I want a LEAVE block to run after a sub has completed,
but only if some condition is True.
# --------------------------------------------------------------------
# Start from this.
sub foo1 {
LEAVE {⋯}
}
The LEAVE block runs after foo() completes, always.
# --------------------------------------------------------------------
# Nope.
sub foo2 {
if $cond {
LEAVE {⋯}
}
The LEAVE block runs here, after the 「if」 block, but still
always (that is, whether $cond is True or False), because it's
a compile-time thing.
}
# --------------------------------------------------------------------
# Solution.
sub foo3 {
if $cond {
}
LEAVE {⋯ if $cond}
}
The LEAVE block runs after foo() completes, again always, but the
「if $cond」 in its block prevents unwanted stuff from being run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment