in reply to Re^4: I'm having a strange bug with basic file input. I'm a total newb.
in thread I'm having a strange bug with basic file input. I'm a total newb.

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/
  • Comment on Re^5: I'm having a strange bug with basic file input. I'm a total newb.
  • Download Code

Replies are listed 'Best First'.
Re^6: I'm having a strange bug with basic file input. I'm a total newb.
by KingCupons (Initiate) on Dec 05, 2008 at 17:21 UTC
    Wow...I wish I could do that. :P

    I would so use it, but my teacher would get suspicious. Thanks a lot. :)