Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Perl Hash Script

by prithviraj (Novice)
on Jan 08, 2013 at 16:06 UTC ( [id://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.

Replies are listed 'Best First'.
Re^3: Perl Hash Script
by roboticus (Chancellor) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1012267]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found