Why don't you use exceptions? An exception is any case when a normal code stream does not follow. Using "return" or "goto" is actually the same, just "not what you want."
(What you really want are continuations, which "return", "goto", "last" and "throw" are all special cases. Although Perl does not have a full continuation, we do have continuation exits, a href = "http://metacpan.org/pod/Continuation::Escape" rel = "nofollow noreferrer"> http://metacpan.org/pod/Continuation::Escape)
In your code example, you write:
do { if(failcond) { last; }
This is probably the same as:
eval { if(failcond){ die 'failcond'; } }
If you want to be complicated and ignore other exceptions:
my $magic = []; eval { if(failcond){ die $magic; } } if ( $@ != $magic) { die;
Or you can use the aforementioned Continuation :: Escape module. But there is no reason to ignore exceptions; it is perfectly acceptable to use them that way.
source share