programming-examples/perl/SystemFunction/Using function 'die' to terminate a program.pl
2019-11-15 12:59:38 +01:00

11 lines
363 B
Perl

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";