Skip to content

Instantly share code, notes, and snippets.

@jhthorsen
Created December 1, 2011 08:50
Show Gist options
  • Save jhthorsen/1415105 to your computer and use it in GitHub Desktop.
Save jhthorsen/1415105 to your computer and use it in GitHub Desktop.
return from inside sub{}
#!/usr/bin/env perl
use strict;
use warnings;
sub foo {
my $res = '';
warn "foo(): @_";
(sub {
warn "ANON(): @_";
$res = shift;
goto RETURN;
})->(@_);
warn "this line will be skipped";
RETURN: $res;
}
warn foo(123);
@jhthorsen
Copy link
Author

could be useful from inside try/catch:

try {
 $res = may_fail();
 goto RETURN;
} catch {
 # handle failure...
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment