open file problem

hi experts!
i have a script that can read a text file. this script runs perfectly when i user free server(virtualave). but when i try to rent a server from my country, it seems that the problem occurs. the server runs in NT. Below is part of the script.

sub open_file {

  local ($filevar, $filemode, $filename) = @_;
  open ($filevar,$filemode . $filename) ||
     die ("Can't open $filename");

above is the sub to  open the file.


and this is the program that runs that function.

the problem is, when i run it, errors appear.the error is:

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

cannot return text file(test.txt) at the following line..
open ($filevar,$filemode . $filename) ||
die ("Can't open $filename");

but this program runs smoothly when i try with virtualave.
hope someone can help.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this a see what it tells you:

  open ($filevar,$filemode . $filename) ||
     (print ("Content-type: text-plain\n\nError codes: $! - $?") && exit);

Also check and see if the file you are trying to open  has the necessary permissions.
kudakAuthor Commented:
ok guadalupe, i've tried yours and this problem occurs.
first, it prompts me to download the perl file.
second wehen i open that perl file, this wording appears:
Error codes: No such file or directory - 0
kudakAuthor Commented:
i've chmoded the perl file and my text file to 755.
KennyIT Application ExecutiveCommented:
Try putting this line in the beginning of your original code. (the one which works on the other server) :

print "Content-type: text/html","\n\n";
If you are promted to download to file it sounds like your server is not corectly configured to run ALL perl files.  I say all because mabe it will run cgi but not pl (I don't know which extension your script has)  But configuration definitly sound like it could be part of the problem.  Then there is the obvious No such file or directory.  The difference is that obiously you dont see this file from a web browser point of view though you do from the command line.  This could be a number of things.  Maybe your variables get correctly set in the command line run and so a full qualified path results, but when run from the  browser for some reason the variables are not set and cause an incomplete path to be specified(?).  Then there are permissions and such.  I would attack configuration first.  Make a stupid little "hello world" prog and make sure it runs with a given extention then take it from there.  Also zxr250 is right about needing to send out the appropriate header to the browser before trying to print out any actual output so...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.