Though I'm sure a few monks can come up with an unpack solution
Here you are =)
use warnings; use strict; use List::Util qw(sum); my $studnum = 0; my $totavg = 0; while (<DATA>) { my ($name, @tests) = unpack ("A20A3A3A3A3", $_); last if $name eq "END"; my $avg = sum(@tests)/4; $totavg += $avg; $studnum++; printf("%-24.20s %6.2f\n", $name, $avg); } $totavg /= $studnum; printf ("\n\n%-24.22s %6.2f\n", $studnum, $totavg); print "Program completed Successfully."; exit 0; __DATA__ Tom Thumb 100096093098 Mickey Mouse 088068095086 Minnie Mouse 078056088098 Donald Duck 098096078100 Tad Pole 100100100100 Mack Aroni 095067089098 Cassie Role 082045088079 Mary Martin 085096093088 Mickey Mantle 088063095086 Darryl Strawberry 078056098098 Donald Trump 098086078100 Steve Young 100078097093 Mack Truck 095067099098 Mel Gibson 082075088079 END 000000000000


holli, /regexed monk/

In reply to Re^5: I'm having a strange bug with basic file input. I'm a total newb. by holli
in thread I'm having a strange bug with basic file input. I'm a total newb. by KingCupons

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.