hihilo has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I have a curious problem with open:

#!/usr/bin/perl $^W=1; use CGI; $| = 1; print "Content-type: text/html\n"; print "Hello, World!\n"; open ($in, "<", "source.list") or die "can't open file: $!"; @src_name = grep /^[A-B]/, <$in>; close $in; print $src_name[0]; print $src_name[$#argument];
It runs fine on command line:
#./test2.pl Content-type: text/html Hello, World! A02008P2350 BSW30905
But if I run it as a cgi script, ie. pointing my browser to http://lapakahi/csodb/test2.pl, it fails to open the file source.list:
Server error! The server encountered an internal error and was unable to complete yo +ur request. Error message: can't open file: No such file or directory at /srv/www/csodb/test2.pl +line 7. , If you think this is a server error, please contact the webmaster. Error 500 lapakahi Thu Oct 28 10:24:57 2010 Apache/2.2.0 (SuSE)
I made sure the file source.list is in the same directory as the script test2.pl, and it is readable by all. Also tried using absolute path for the file. Same result.

Any suggestions and advices will be greatly appreciated.

Replies are listed 'Best First'.
Re: curious problem with open
by Corion (Patriarch) on Oct 28, 2010 at 20:51 UTC

    You are using a relative filename, but the current directory is not what you think it is. Use an absolute filename to open the file.

      That did it! I thought I tried full path before but not getting anywhere...

      Thanks for the fix!

Re: curious problem with open
by choroba (Cardinal) on Oct 28, 2010 at 21:02 UTC
    Two newlines are needed after Content-type line in the header, BTW.
Re: curious problem with open
by aquarium (Curate) on Oct 29, 2010 at 03:05 UTC
    also...what you're seeing is the server (apache) error response. when debugging: use CGI::Carp qw(fatalsToBrowser) so you can see perl errors if any.
    the hardest line to type correctly is: stty erase ^H