Perl CGI: No such file and directory: Yet file exists?

This technically a homework problem but I just need help solving this strange issue. The code is kinda long, I tried posted only the relevant parts.

  1. The problem statement, all variables and given/known data:

I receive this error:

got error No such file or directory (2)

at:

open(GRADES,"<<$grades") or die "got error $! (".($!+0).")\n";

line 49 in CreateExam.pm called from submit.cgi, linked below.

  1. Relevant commands, code, scripts, algorithms:
    submit.cgi:
	my $check = CreateExam->new("/var/www/roger/homeworks/hw13/exam4.txt","/var/www/roger/homeworks/hw13/answers4.txt","/var/www/roger/homeworks/hw13/grades4.txt",$pathroot);

CreateExam.pm:

sub new {
	my ($class,$file,$answers,$grades,$script) = @_;
	#print "<p>in new: file: $file, grades: $grades</p>\n";
	return bless {'file'=>$file,'answers'=>$answers,'gradefile'=>$grades,'script'=>$script},$class;
}
my $grades = $self->{'gradefile'};
open(GRADES,"<<$grades") or die "got error $! (".($!+0).")\n";
  1. The attempts at a solution (include all code and scripts):

I tried all of those recommendations: I remove any whitespace, I put in a check for any nonprintable characters, I hard-coded the path.

To make sure it wasn't a permissions issue, I installed suExec-custom for debian, all cgi scripts run under my UID, that didn't help.

I'm running this on debian with Apache

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

SUNY Polytechnic, Formerly SUNY Institute of Technology
100 Seymour Rd Utica NY 13502
CS 351 Web Development and Internet Programming
Scott Spetka scott@sunyit.edu

Does it work when run from the commandline?

I just tested it and yes it does work from command line

script:

#!/usr/bin/perl
use CGI qw(:standard);
use CGI qw(:standard Vars);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use File::Basename;
use lib dirname(__FILE__);
use CreateExam;

my $cgi = CGI->new(\*STDIN);

print $cgi->header();
print $cgi->start_html("test");

my $check = CreateExam->new("/var/www/roger/homeworks/hw13/exam4.txt","/var/www/roger/homeworks/hw13/answers4.txt","/var/www/roger/homeworks/hw13/grades4.txt",0);

print "<p>\n";
print $check->tooktest("dancksj");
print "</p>\n";

print $cgi->end_html();
exit;	

output:

jddancks@debian-macbook:/var/www/roger/homeworks/hw13$ ./testcmdline.pl

Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>
1</p>

</body>
</html>

I also tested it in the browser and it worked there as well. I copy/pasted

my $check = CreateExam->new("/var/www/roger/homeworks/hw13/exam4.txt","/var/www/roger/homeworks/hw13/answers4.txt","/var/www/roger/homeworks/hw13/grades4.txt",0);

right from submit.cgi

Sorry, I misled you guys.

The problem was I was opening a file like so:

open(GRADES,"<<$grades") or die "got error $! (".($!+0).")\n";

which by itself doesn't make sense. And then I tried to write to the screwed up file handle. I noticed it by chance. Such a bizarre error message.

Thanks anyways Corona.