I just wanted to say that I'm a new PERL programmer and I have lots of things to learn. I've been working on this program for some time. I'm having trouble with opening and closing and writing to my file. Here's what I got so far:
use strict; my @data; my $avg; my $dev; my $std; my $tmp; my $grade; my $line; open(IN, "pa5c.dat") || die ("Can't open file $!\n"); while($line = <IN>){ chomp ($line); my $tmp = [split /:/]; $avg += $tmp->[1]; push @data, $tmp; } $avg = scalar(@data) ? $avg /= @data : 0; my $std = 0; for (@data) { $std += abs($_->[1] - $avg) } $std = scalar(@data) ? $std /= @data : 0; open(OUT, ">pa5c.dat") || die ("Can't open file $!\n"); for (@data) { my $grade; my $dev = ($_->[1] - $avg) / $std; if ($dev >= 1) { $grade = 'A' } elsif ($dev >= (1/3)) { $grade = 'B' } elsif ($dev >= (-1/3)) { $grade = 'C' } elsif ($dev > -1) { $grade = 'D' } else { $grade = 'E' } print OUT join (':', $_->[0], $_->[1], $grade) . "\n"; } close OUT; __END__#pa52.pl
The pa5c.dat file contains:
Smith:70 Jones:74 Rider:80 High:82 Billie:68 Smithsonville:76
Now if my program runs correctly, my program should assign letter grades to the students.

In reply to Filehandles - opening/closing a filehandle by yabba

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.