# Adjusted.pm 18sep14waw package Adjusted; use warnings FATAL => 'all'; use strict; use List::Util qw(sum); my %pos = qw(A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 { 0); my %neg = qw(J 1 K 2 L 3 M 4 N 5 O 6 P 7 Q 8 R 9 } 0); my %all = (%pos, %neg); my $suffices = join '', keys %all; sub value { my ($val, # value (string) to be adjusted and returned as number ) = @_; # convert suffix of valid value to digit. $val =~ s{ \A \d{8} ([\Q$suffices\E]) \z }{$all{$1}}xms or die "bad value: '$val'"; my $suffix = $1; # save capture group (just in case...) # negate value if suffix in negative group, return as numeric. return (exists $neg{$suffix} ? -1 : 1) * $val; } sub values_summed { # throws exception if no arguments # return rounded, summed, adjusted values as numeric scalar. return 0 + sprintf '%.2f', sum(map value($_), @_) / 100; } 1; # end Adjusted.pm