prithviraj has asked for the wisdom of the Perl Monks concerning the following question:
I am not getting the exact output. Where am I going wrong? Please help. Thanks in advance.#!/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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl Hash Script
by muba (Priest) on Jan 08, 2013 at 15:59 UTC | |
by prithviraj (Novice) on Jan 08, 2013 at 16:10 UTC | |
by muba (Priest) on Jan 08, 2013 at 16:16 UTC | |
by prithviraj (Novice) on Jan 08, 2013 at 16:18 UTC | |
|
Re: Perl Hash Script
by roboticus (Chancellor) on Jan 08, 2013 at 15:42 UTC | |
by prithviraj (Novice) on Jan 08, 2013 at 16:06 UTC | |
by roboticus (Chancellor) on Jan 08, 2013 at 17:18 UTC |