use strict; use warnings; use Test::More; use Test::More::UTF8; # loads utf8.pm sub convert_currency { my %map = ( '$¥' => sub { $_[0] * 105.4 }, '¥$' => sub { $_[0] * 0.0095 }, '$€' => sub { $_[0] * 0.89 }, '€$' => sub { $_[0] * 1.12 }, ); my ($from, $to, $amount) = @_; my $converter = $map{"$from$to"}; return sprintf( '%.3f', $converter->($amount) ); } is( convert_currency('$', '¥', 5), '527.000', '$ -> ¥' ); is( convert_currency('€', '$', 42.02), '47.062', '€ -> $' ); is( convert_currency('$', '€', 42.02), '37.398', '$ -> €' ); done_testing;