Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Perl Hash Script

by prithviraj (Novice)
on Jan 08, 2013 at 16:06 UTC ( #1012267=note: print w/ replies, xml ) Need Help??


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

I get the output as:

Sorted Employee Numbers: 23545 1 periods 20 hours 20 average 32543 1 periods 10 hours 10 average 41234 1 periods 9 hours 9 average 57543 1 periods 9 hours 9 average 67845 1 periods 8 hours 8 average 84395 1 periods 6 hours 6 average The number of work periods is 6 Total number of hours is 63 Average number of hours per work period is 10.5
But the output I am expecting is:
Sorted Employee Numbers: 23545 1 periods 20 hours 20 average 32543 1 periods 10 hours 10 average 41234 1 periods 9 hours 9 average 57543 1 periods 9 hours 9 average 67845 1 periods 8 hours 8 average 84395 1 periods 6 hours 6 average The number of work periods is 9 Total number of hours is 63 Average number of hours per work period is 7
Please help.


Comment on Re^2: Perl Hash Script
Select or Download Code
Re^3: Perl Hash Script
by roboticus (Canon) on Jan 08, 2013 at 17:18 UTC

    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012267]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-09-01 22:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls