[32758] in Perl-Users-Digest
Perl-Users Digest, Issue: 4022 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 29 03:09:41 2013
Date: Thu, 29 Aug 2013 00:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 29 Aug 2013 Volume: 11 Number: 4022
Today's topics:
Re: approach to calculating pay <rweikusat@mobileactivedefense.com>
Re: korean character sets <cwilbur@chromatico.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Aug 2013 11:08:43 +0100
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: approach to calculating pay
Message-Id: <878uzmf7pw.fsf@sapphire.mobileactivedefense.com>
ccc31807 <cartercc@gmail.com> writes:
> This isn't strictly Perl question, but I've implemented this in Perl, and will re-implement it in Perl.
>
> I have several contracts to build about five times a year. Among other provisions, the 'contract price' is one of the provisions. While some are negotiated (and therefore beyond my ken) most can be calculated. I have built a function to calculate the pay, to which I pass about nine different parameters, and it returns a discrete integer, the 'contract price.' Rather than describe it, there is some semi-pseudo code below. As you will note, it consists of a large number (almost 100) of if-elsif statements.
>
> Question: can someone recommend a better approach?
>
> Thanks, CC.
>
> my %contracts = get_contract_info_from_database();
> foreach my $contract (keys %contracts)
> {
> #initialize about 20 different variables that constitute the contract terms
> my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) = parse_row_from_hash($contracts{$contract);
> $contract_price = calculate_contract_price($site, $rank, $experience, $ftptstat, $jobtype, $level ...);
> #build and print each contract
> }
>
> sub calculate_contract_price
> {
> my ($site, $rank, $experience, $ftptstat, $jobtype, $level ... ) = @_;
> my $contract_price = 0;
> if ($jobtype eq 'a')
> {
> if ($level == 1)
> {
> if ($rank eq 'A')
> {
> # etc for the rest of the nine parameters until, at the bottom, I have this:
> # $contract_price = $hours * $production * 1288;
> # (1288 constitutes the approved price for the work to be performed at the
> # particular level, rank, site, time status, job type, etc.
> }
> elsif ($rank eq 'B')
> {
>
> }
> elsif ($rank eq 'C')
> {
>
> }
> else { warm "ERROR in rank, $rank\n"; }
> }
[...]
Hmm .... "don't make such mess of it next time"?. I think it is highly
unlikekly that you really need an orthognal 9D-space to classify the
type of contracts you have to deal with as this would either mean an
enormous amount of contracts or pretty much 'no classification at
all'. If you can express some of your input variables as functions of
some of the other input variables or omit them altogether, the problem
itself would become much simpler.
Apart from that, the 'hash idea' is generally sensible. A useful
simplication could be to create a 'compound key' from your input
values by joining them together with some 'neutral' character. Perl
has some builtin support for this (see description of $; in 'perldoc
pervar') but I think creating real 'compound keys' would be a better
choice. The set of 'valid contracts' would then exist in a single
hash and the if - cascades would be replaced by joining the input
values and doing a lookup in this hash.
------------------------------
Date: Wed, 28 Aug 2013 10:17:18 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: korean character sets
Message-Id: <87wqn5aoi9.fsf@chromatico.net>
>>>>> "C" == Cal Dershowitz <cal@example.invalid> writes:
C> I think my machine or my brain wasn't working.
Finally we are all on the same page.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4022
***************************************