Created
March 29, 2011 09:20
-
-
Save olostan/892072 to your computer and use it in GitHub Desktop.
Solution for POS Terminal (anti-howto in 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(sum); | |
use POSIX qw(floor); | |
# 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 $P{$_} ? $_{$_} * $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