package Op; use warnings; use strict; my %dispatch = (plus => sub { $_[0] + $_[1] }, minus => sub { $_[0] - $_[1] }, divide => sub { $_[0] / $_[1] }, times => sub { $_[0] * $_[1] }); sub result { my ($args) = @_; my $operand1 = $args->{op1}; my $operand2 = $args->{op2}; my $operation = $args->{op}; my $is_integer = $args->{int}; my $action = $dispatch{$operation} or die "Unknown operation '$operation'.\n"; my $result = $action->($operand1, $operand2); $result = int $result if $is_integer; return $result } __PACKAGE__