what is the best way to break out of a subroutine & continue processing the rest of the script?
ie
#!/usr/bin/perl
use strict;
use warnings;
&mySub;
print "we executed the sub partway through & continued w/ the rest
of the script...yipee!\n";
sub mySub{
print "entered sub\n";
#### Options
#exit; # will kill the script...we don't want to use exit
#next; # perldoc says not to use this to breakout of a sub
#last; # perldoc says not to use this to breakout of a sub
#any other options????
print "we should NOT see this\n";
}
At the expense of stating the obvious the best way of returning for a subroutine is ……
Unless there is some hidden subtlety in the question that isn’t made clear
Edit – maybe I see what you are getting at
If you write a loop, then a valid way of getting out of the loop is to use
lastIf you refactor this, you might end up with a using last to get out of the subroutine.
This means you are using
lastwhere you should be usingreturnand if you have wanings in place you get the error :