Created
February 27, 2017 09:00
-
-
Save olostan/dea33ee201334f3c9c1e2d5df094b6fa to your computer and use it in GitHub Desktop.
Price Calculator - Test Assigment (perl)
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
use List::Util qw(reduce sum); | |
use POSIX; | |
# Pricelist | |
%P = ( "A" => [1.25, 3, 3], "B" => 4.25, "C" => [1,6,5], D=> 0.75 ); | |
# Sale scanning | |
$_{$_}++ for split (//,qw(ABCDABA)); | |
# Calculate total | |
print "Total = ".sum map { | |
(ref(\$PR) eq 'SCALAR')? ($_{$_} * $P{$_}) : floor($_{$_} / $P{$_}->[1])*$P{$_}->[2]+($_{$_} % $P{$_}->[1])*$P{$_}->[0]; | |
} keys(%_); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment