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";

When is p the complement of ch?
When in the company of Erlish!

In reply to Not very perlish? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.