I get the output to be

Totals GIRAFFE | 2 | 1 | 50% LEOPARD | 1 | 1 | 100% MONGOOSE | 1 | 1 | 100% MONKEY | 2 | 2 | 100% HIPPO | 4 | 3 | 75% MEERKAT | 1 | 0 | 0% LION | 1 | 1 | 100% ZEBRA | 3 | 3 | 100% ---------------------------------------- Total | 15 | 12 | 80%
#!/usr/bin/perl use strict; use warnings; use Spreadsheet::BasicRead; # Data file # CLASS PUPIL M/F READING PROGRESS my $xlsx_WSD = "C:\\Temp\\data1.xlsx"; my @header; my %stats = (); my $i = 0; if ( -e $xlsx_WSD ) { my $ss = new Spreadsheet::BasicRead($xlsx_WSD) or die; while ( my $row = $ss->getNextRow() ) { my $class = $row->[0]; my $reading = $row->[3]; if (++$i == 1){ push @header,$row; } else { $stats{$class}{'count'}++; if ($reading < 6){ $stats{$class}{'limit'} += 1 ; } else { $stats{$class}{'limit'} += 0; } } } } print "\nTotals\n"; my %total = (); my $fmt = "%-15s | %5d | %5d | %5d%%\n"; for my $class (keys %stats){ my $rec = $stats{$class}; my $limit = $rec->{'limit'}; my $count = $rec->{'count'}; my $pc = 100 * $limit / $count unless ($count == 0); printf $fmt, $class, $count, $limit, $pc; $total{'count'} += $count; $total{'limit'} += $limit; } my $pc = 100 * $total{'limit'} / $total{'count'} unless ($total{'count'} == 0); print '-'x40,"\n"; printf $fmt, 'Total', $total{'count'}, $total{'limit'}, $pc;
poj

In reply to Re: Perl script to calacuate percentage statistics, does not display 0% in output by poj
in thread Perl script to calacuate percentage statistics, does not display 0% in output by john.tm

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.