Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
My program accepts 3 percentile inputs ($pre, $amble, $post ) which should sum to 100, if they don't I wish to correct them such that they do.
If the sum is greater than 100 I wish to favour amble, then pre, then post.
If the sum is less than 100, post takes up the slack;
The following achieves my aim, but it doesn't seem very elegant (perlish), and I am sure that it can be improved upon.
$pre = (shift) % 100; $amble = (shift) % 100; $post = (shift) % 100; if ($pre + $amble + $post != 100 ) { $pre = 100 - $amble if ( $amble + $pre > 100 ); $post = 100 - ($amble + $pre) if ( $pre + $amble + $post != 100 ); } print "$pre + $amble + $post = ", <br> $pre + $amble + $post , "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Not very Perlish? (note the capital P ;)
by frankus (Priest) on Jun 10, 2002 at 10:13 UTC | |
|
Re: Not very perlish?
by Abigail-II (Bishop) on Jun 10, 2002 at 11:37 UTC | |
|
(tye)Re: Not very perlish?
by tye (Sage) on Jun 10, 2002 at 16:48 UTC | |
|
Re: Not very perlish?
by particle (Vicar) on Jun 10, 2002 at 11:56 UTC | |
|
Re: Not very perlish?
by talexb (Chancellor) on Jun 10, 2002 at 14:30 UTC | |
|
Re: Not very perlish?
by Anonymous Monk on Jun 10, 2002 at 23:54 UTC |