in reply to Re^2: Perl Hash Script
in thread Perl Hash Script

prithviraj:

The only difference I see is the totals at the end. If that's the case, you should probably accumulate the totals in the first loop.

However, I rather suspect that you really don't want that. Your data shows multiple work periods for at least one employee, yet your output doesn't indicate it. I'm thinking that what you *really* want to do is to track both the number of periods *and* the total time for each employee. You might try it something like:

while (my $series = shift @series) { my $nums = shift @series; $empwork{$series}{TTL} += $nums; $empwork{$series}{CNT}++; }

Then later you can show the number of periods and the total time and compute the average.

for my $empnum (sort keys %empwork) { ... my $periods = $empwork{$empnum}{CNT}; ... }

...roboticus

When your only tool is a hammer, all problems look like your thumb.