Created
June 7, 2011 09:37
-
-
Save olostan/1011958 to your computer and use it in GitHub Desktop.
POS Terminal (Perl solution)
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 | |
map { $_{$_}++ } 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