On Thu, 17 Feb 2005 06:06:30 +1000, Alfred Vahau <[EMAIL PROTECTED]> wrote: > > $inputfile = 'gpa.dat'; > open (INF, "<$inputfile") || die "can't open file $inputfile $!:\n"; > > But this is another problem that I can address later. > ********* >
my $inputfile = 'gpa.dat' ; strict wants you to declare the scope of the variable. It's just a good thing to do. > >my %grades = ( A => 4, B => 3, C=> 2, D=> 1, F => 0 ) ; > ># lookup hash for the grades > > > > > Thank you. Keeps tracking easier. > > >my %studcredit ; > ># we'll store the credits attempted here > > > > > > > >my %studpoints ; > ># we'll store the honor points here > > > >while (<>) { > > chomp; > > my ($id, $grade, $cred) = split /\s/, $_ ; # or just split > > > > > I'll use /\s+/ just in case of additional white spaces in the real data > > > next unless $grade =~ /[ABCDF]/; > > > > > The use of character classes clearly skipped my mind. Just to be sure of > cases, I'll use /[a-fA-F]/ \s+ isn't a bad idea. Be careful with you classes here, though. [a-fA-F] matches both 'e' and 'E'. Try '/[ABCDF]/i'. > Id 316 gpa = 1.40 is confirmed. > Id 216 = 1.64 is different from one I quoted (1.73). > > Ankur Gupta in an earlier posting quoted 1.98 for id 216 so I will have > to check the calculations again > for non-allowed grades. Some of the data may not have cut and pasted correctly. HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>