Looking at "$client_total = {$key} = $client_total/10;", I recommend you read "perlintro -- a brief introduction and overview of Perl".

Here's how you might go about extracting data from a file, storing that data in a data structure, performing calculations on that data, and subsequently storing the results in the same data structure. I've reused the data, and a small amount of the code, from ++kennethk's earlier post. This is intended to give you some pointers as I've really no idea what you're actually trying to achieve.

#!/usr/bin/env perl use strict; use warnings; use List::Util qw{sum}; my %data = (client => {}, all => {}); my $client = $data{client}; my $all = $data{all}; while (<DATA>) { my ($name, $amount) = split; push @{$client->{$name}{amounts}}, $amount; } for (sort keys %$client) { push @{$all->{clients}}, $_; $client->{$_}{total} = sum @{$client->{$_}{amounts}}; $all->{total} += $client->{$_}{total}; } for (keys %$client) { $client->{$_}{percent} = $client->{$_}{total} * 100 / $all->{total +}; } use Data::Dump; dd \%data; __DATA__ a 1 b 5 a 3 b 7 c 9 a 2

Output:

{ all => { clients => ["a", "b", "c"], total => 27 }, client => { a => { amounts => [1, 3, 2], percent => 22.2222222222222, total => + 6 }, b => { amounts => [5, 7], percent => 44.4444444444444, total => 12 + }, c => { amounts => [9], percent => 33.3333333333333, total => 9 }, }, }

-- Ken


In reply to Re^4: Running Total Array or Hash by kcott
in thread Running Total Array or Hash 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.