#!/user/bin/perl use strict; use warnings; print "Welcome to the mathq program\n"; while (1) { print "Enter a number\n"; chomp(my $n = ); die "Goodbye\n" if $n eq 'q'; chomp(my $m = ); print "$n + $m = ", $n+$m, "\n", "$n - $m = ", $n-$m, "\n", "$n x $m = ", $n*$m, "\n", $m == 0 ? '' : ("$n / $m = ", $n/$m), "\n"; } __END__ #### #!/user/bin/perl use strict; use warnings; print "Welcome to the mathq program\n"; INPUT: while (1) { print "Enter a number\n"; chomp(my $n = ); die "Goodbye\n" if $n eq 'q'; chomp(my $m = ); for ($n,$m) { warn "Invalid input: Type a number or 'q' to quit\n" and next INPUT unless /\A\d+\z/; # use your own more refined validation there } print "$n + $m = ", $n+$m, "\n", "$n - $m = ", $n-$m, "\n", "$n x $m = ", $n*$m, "\n", $m == 0 ? '' : ("$n / $m = ", $n/$m), "\n"; } __END__ #### ($n,$m) = map { ;no warnings 'numeric'; $_+0; } $n, $m;