5.8. Dividing two numbers given by the user

Ask the user for two numbers and divide the first by the second number.

Example 5-8. examples/scalars/divide.pl

#!/usr/bin/perl
use strict;
use warnings;

print "First number: ";
my $x = <STDIN>;
chomp $x;

print "Second number: ";
my $y = <STDIN>;
chomp $y;

my $z = $x / $y;
print "The result is $z\n";

$ perl examples/divide.pl
First number: 27
Second number: 3
9
$ perl examples/divide.pl
First number: 27
Second number: 0
Illegal division by zero at examples/divide.pl line 9, <STDIN> line 2.