Created
May 20, 2014 01:32
-
-
Save tacitochaves/ab36c5ad1bf9cd687e46 to your computer and use it in GitHub Desktop.
Operação
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.014; | |
say "####################################"; | |
say "Program of sum and difference."; | |
say "####################################"; | |
say "Entre com a opção desejada."; | |
say "1 - For sum"; | |
say "2 - For difference"; | |
say; | |
chomp( my $opcao = <STDIN> ); | |
if ( $opcao ne 1 and $opcao ne 2 ) { | |
say "Opção inválida"; | |
exit(1); | |
} elsif ( $opcao eq 1) { | |
print "Please, inform the first number: "; | |
chomp( my $num1 = <STDIN> ); | |
print "Please, inform the second number: "; | |
chomp( my $num2 = <STDIN> ); | |
say &sum($num1,$num2); | |
} else { | |
print "Please, inform the first numbeer: "; | |
chomp( my $num1 = <STDIN> ); | |
print "Please, inform the second number: "; | |
chomp( my $num2 = <STDIN> ); | |
say &dif($num1,$num2); | |
} | |
sub sum { | |
my $total; | |
my @numbers = @_; | |
foreach (@numbers) { | |
$total += $_; | |
} | |
return $total; | |
} | |
sub dif { | |
my $num1 = shift; | |
my $num2 = shift; | |
return $num1 - $num2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment