This a quick implementation of the algorithm description I gave before:
#!/usr/bin/env perl use strict; use warnings; my %user_weight = (DREW => .5, TIM => 2,); my ($tot_users, $tot_non_weighted, $tot_events); while (<DATA>) { # Stuff data into Hash and get count of total events and users my ($user, $val) = split; $tot_events += $val; $tot_users++; $tot_non_weighted ++ unless exists $user_weight{$user}; } my $number_of_weighed_parts; $number_of_weighed_parts += $_ for values %user_weight; my $indiv_part = $tot_events / ($tot_non_weighted + $number_of_weighed +_parts); print "The $tot_non_weighted non_weighted workers get each $indiv_part +\n"; for my $weighted_user (keys %user_weight) { print "$weighted_user gets ", $indiv_part * $user_weight{$weighted +_user}, "\n"; } __DATA__ TIM 150 JOE 124 JACK 111 KATE 145 DREW 177
And this prints the following output:
$ perl weight.pl The 3 non_weighted workers get each 128.545454545455 DREW gets 64.2727272727273 TIM gets 257.090909090909
which seems correct (at least if I understood correctly what you are trying to do). You would probably want to add some rounding, but I leaves that to you.

Edit 15:41 UTC: corrected a bug in the above code and the output.

Edit2 16:40 UTC: I had not seen moritz's solution when I posted my messages above. My proposed solution (be it in English or in Perl code) is to a large extent equivalent, sorry for posting almost the same thing.


In reply to Re: Weighted Calculation by Laurent_R
in thread Weighted Calculation by dirtdog

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.