My question in Perl using simple hashes is: Read a series of employee numbers and daily working hours from standard input, one set perl line.The employee number and the hours worked should be separated by a space. Use hashes and calculate the total number of hours worked and the average number of hours per work period. Print out a report by sorted employee number, the number of work periods, the total hours worked, and the average number of hours per work period. Assume that some of the employees are on a part-time schedule and do not work the same number of days or hours as regular employees. My code is:
#!/usr/bin/perl use strict; use warnings; my @series = qw(41234 9 67845 8 32543 10 84395 7 57543 9 23545 11 2354 +5 1 23545 2 23545 6); my $total_periods = 0; my $total_hours = 0; my %empwork; while (my $series = shift @series) { my $nums = shift @series; $empwork{$series} += $nums; } print "Sorted Employee Numbers:\n"; foreach my $empnum(sort keys %empwork) { my $periods=0; $periods++; my $hours = 0; $hours += $empwork{$empnum}; my $avg = $hours/$periods; $total_periods += $periods; $total_hours += $hours; print "$empnum\n$periods periods\n$hours hours\n$avg average\n\n"; } my $grand_avg = $total_hours/$total_periods; print "The number of work periods is $total_periods\n"; print "Total number of hours is $total_hours\n"; print "Average number of hours per work period is $grand_avg\n";
I am not getting the exact output. Where am I going wrong? Please help. Thanks in advance.

In reply to Perl Hash Script by prithviraj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.