#!/usr/bin/env perl use utf8; ############################################################################### # This program demonstrates how to prompt the user for input. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use Error::Simple; use Nice::Try; use Utils; use strict; use warnings; # Try/Catch is added to Perl with cpan -i Syntax::Keyword::Try MAIN: { binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); binmode(STDIN, ":utf8"); try { my $favoriteInt; my $favoriteLong; my $favoriteDouble; my $favoriteIntInput; $favoriteIntInput = Utils::prompt("What is your favorite small integer? "); $favoriteInt = Utils::stoi($favoriteIntInput); my $favoriteLongInput; $favoriteLongInput = Utils::prompt("What is your favorite large integer? "); $favoriteLong = Utils::stoi($favoriteLongInput); my $favoriteDoubleInput; $favoriteDoubleInput = Utils::prompt("What is your favorite floating point? "); $favoriteDouble = Utils::stod($favoriteDoubleInput); my $sum = $favoriteInt + $favoriteLong + $favoriteDouble; print Utils::messageFormat("All together they add up to \{0:f\}!", $sum), "\n"; } catch (Error::NumberFormatException $ex) { print "Bad input! " . $ex, "\n"; } catch (Error::Simple $ex) { print "Don't know what went wrong!\n"; } }