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 },
},
}
|