Skip to content

Instantly share code, notes, and snippets.

@olostan
Created June 7, 2011 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olostan/1011958 to your computer and use it in GitHub Desktop.
Save olostan/1011958 to your computer and use it in GitHub Desktop.
POS Terminal (Perl solution)
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