Using function 'die' to terminate a program
print "Please enter a numerator: ";
chomp( $numerator = <STDIN> );
print "Please enter a denominator: ";
chomp( $denominator = <STDIN> );
# if condition is false, program prints message and terminates
$denominator != 0 or die "Cannot divide by zero";
# executes only if $denominator is not 0
print "\nThe result is ", $numerator / $denominator, "\n";
Related examples in the same category