Monday, January 18, 2010

How to break from if - else in Perl

One of the ways to break from if - else in Perl is to use goto

if ($num =~ /^\d+$/){
if($num == 13){
goto ENDOFIF;
}
} else {
print "Number not found.\n";
ENDOFIF:
}

So if the number is 13 then it will break from the if and place the control right at the end of outer if.

No comments: