Try this (hope'll work)

$pathto='c:/perl/eg/grades.txt'
open (GRADES,$pathto) or die ....

It works in Unix for sure , and probably in W too
If you use the file grade.txt  for many times in your script and if you change it's 
location , you'll change your script just once in the "pathto" variable .
Please let me know if worked . 

On Tue, 3 Jul 2001 12:45:12 -0600, Customer Service <[EMAIL PROTECTED]> 
 wrote:
> O enlightened ones, here is my question:
> I am going through the llama book  (which, by the way, is the most useful
> tool
> I have bought so far for perl reference) in order to learn perl.  On page 10
> is a simple script which I copied and have attempted to execute for the last
> 1/2 hour.  Please tell me what is wrong!
> I'm using ActiveStatePerl5.6.1 and Apache web server on M$ win98se.
> 
> ##############perl script   file name: gradation.pl ##################
> #!c:/perl/bin/perl -w
> 
> open(GRADES, "c:\perl\eg\grades.txt") or die "Can't open grades: $!\n";
> while ($line = <GRADES>) {
>         ($student, $grade) = split(" ", $line);
>         $grades{$student} .= $grade . " ";
> }
> 
> foreach $student (sort keys %grades) {
>         $scores = 0;
>         $total = 0;
>         @grades = split(" ", $grades{$student});
>         foreach $grades (@grades) {
>                 $total += $grade;
>                 $scores++;
>         }
>         $average = $total / $scores;
>         print "$student: $grades{$student}\tAverage: $average\n";
> }
> 
> ##### my text file is as follows, and is called "grades.txt" in same path as
> gradation.pl
> 
> Noel  25
> Ben  76
> Clementine  49
> Norm  66
> Chris  92
> Doug  42
> Carol  25
> Ben  12
> Clementine  0
> Norm  66
> ....
> 
> # Resulting error messages
> 
> Unrecognized escape \p passed through at c:\perl\eg\gradation.pl Line 3
> Unrecognized escape \g passed through at c:\perl\eg\gradation.pl Line 3
> Can't open grades: No such file or directory
> ######### That's it #########
> 
> 
> Thanks for any help.
> Standing by with a water hose,
> Nathan

Reply via email to