| [reply] |
As others have pointed out, you are light on specifics. The more specific you are, the more helpful we can be. This includes sample input, scrubbed as necessary and wrapped in code tags; desired output, wrapped in code tags; and attempted code or at least a description of your algorithm. See How do I post a question effectively?.
each record has the name of the client
This sounds like indexing results by strings, which says "use a hash" to me. Algorithmically, that might look something like:
#!/usr/bin/perl -w
use strict;
my %sum;
while (<DATA>) {
my ($name, $value) = split;
$sum{$name} += $value;
}
for my $key (sort keys %sum) {
print "$key: $sum{$key}\n";
}
__DATA__
a 1
b 5
a 3
b 7
c 9
a 2
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
| [reply] [d/l] |
Hello All,
Thank you KennethK,
This is exactly what I needed, just enough to give me direction. Worked like a charm!
| [reply] |
Hello,
I guess I have 1 additional component.
Assuming I display everything properly can I manipulate the total with a math formula and put it back in the array prior to printing it?
for my $key (sort keys %client_total) {
$client_total = {$key} = $client_total/10;
}
for my $key (sort keys %client_total) {
print "$key: $client_total{$key}\n";
}
I'm not clear on on how to manipulate the value, the above gives me an error.
Thanks!! | [reply] [d/l] |
Without seeing your input file or the output you desire, it is hard to give a code example. However, I think a hash might be preferable to an array due to potentially easier access. perlintro | [reply] |