Using function 'die' to terminate a program : die « System Functions « Perl






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

1.The die function exits the Perl script and prints out an error message to STDERR
2.Using die to ouput error message