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

Hi Monks, when i try to execute the following code:
#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI qw(:standard); use DBI; use DBD::mysql; use Mail::Sendmail; print header( -charset=>"iso-8859-7" ); print start_html( -title=>"Ψυχωφελή Πνευματικά Κείμενα!", -background= +> "../data/images/night.jpg" ) +; @files = <../data/texts/*.txt>; $file = $files[int(rand(@files))]; print "@files\n\n"; print "$file\n\n"; open(IN, "<$file") or die $!; @data = <IN>; close(IN); print @data;
it works ok if i do perl test.pl. All variables have contents inside them and the $file was opened and executed just fine! The Funny thing is when i try to execute the above code as a perl cgi script in my browser. instead of running it gives me the following error!
Software error: at /var/www/cgi-bin/test.pl line 17.
Isn't this strange? How its not working as a perl cgi script? here is also the output that perl test.pl is producing when i execute it:
[root@localhost cgi-bin]# perl test.pl Content-Type: text/html; charset=iso-8859-7 <?xml version="1.0" encoding="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-U +S"><head><title>Ψυχωφελή Πνευματικά Κείμενα!</title> </head><body background="../data/images/night.jpg">../data/texts/Damas +kinos.txt ../data/texts/Efraim1.txt ../data/texts/Iosif1.txt ../data/ +texts/Iosif2.txt ../data/texts/Neilos.txt ../data/texts/nikos.txt ../ +data/texts/Theoklitos1.txt ../data/texts/Theoklitos2.txt ../data/texts/Theoklitos1.txt &#65533;&#65533;&#65533; &#65533;&#65533; &#65533;&#65533;&#65533;&#65 +533;&#65533;. &#65533; &#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533; &# +65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#6553 +3;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533; & +#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533; &#65533;. &#65533;&#65533;&#65533;&#65533;&#65533; &#65533; &#65533;&#65533; &#6 +5533;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533; &#65533;&#6553 +3;&#65533;&#65533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533; +&#65533;. &#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&# +65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#6553 +3;&#65533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65533;& +#65533; &#65533;&#65533;, &#65533; &#65533;&#65533; &#65533;, &#65533 +; &#65533;&#65533;&#65533;&#65533;&#65533;. &#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533;& +#65533;&#65533; &#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65 +533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;& +#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#6553 +3;&#65533; &#65533;&#65533; &#65533;&#65533;&#65533;&#65533; &#65533; +&#65533;&#65533; &#65533;&#65533;&#65533; &#65533;&#65533;. &#65533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65 +533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; +&#65533;&#65533;, &#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&# +65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; &#655 +33;&#65533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65533; + &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;. &#65533;&#65533; &#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65 +533;, &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533 +;&#65533; &#65533;&#65533;&#65533; &#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33; &#65533;&#65533;. &#65533;&#65533;&#65533;&#65533;&#65533; &#65533; &#65533;&#65533;&#65 +533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65533; &#6553 +3;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;, &#65533;&#65533; +&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533;, &# +65533;&#65533;&#65533;, &#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533;&#65533;&#65533; &#65533;&#65533; &#65533; &#65533; &#6553 +3;&#65533; &#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533; +&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33; &#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#655 +33;, &#65533;&#65533;&#65533;&#65533;&#65533;, &#65533;&#65533;&#6553 +3;&#65533;&#65533; &#65533; &#65533; &#65533;&#65533;&#65533; &#65533 +;. &#65533;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#655 +33;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;, &#65533;&#65533; +&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533; &#65533;&#6 +5533;&#65533; &#65533; &#65533;&#65533;. &#65533;&#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#6 +5533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; +&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533; & +#65533;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#655 +33;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;& +#65533;&#65533;&#65533; &#65533;&#65533;&#65533;&#65533;&#65533;&#655 +33;&#65533; &#65533;&#65533;&#65533;&#65533;, &#65533; &#65533;&#6553 +3;&#65533; &#65533;&#65533;&#65533; &#65533; &#65533;&#65533;&#65533; +&#65533; &#65533;&#65533; &#65533; &#65533;&#65533;&#65533;. &#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533; &#65533;&#65 +533; &#65533; &#65533;&#65533;&#65533; &#65533;&#65533;&#65533;, &#65 +533;&#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533;&#65533; + &#65533;&#65533;&#65533;&#65533;&#65533; &#65533;&#65533; &#65533;&# +65533; &#65533; &#65533; &#65533;&#65533;&#65533; &#65533; &#65533;&# +65533;&#65533; &#65533; &#65533; &#65533;&#65533;&#65533;&#65533;&#65 +533;&#65533;&#65533; &#65533; &#65533;.

The data are in greek thats why is showing this way?
What do you think? Why it is not running in your opinion?

20040211 Edit by Corion: Fixed formatting and changed ode tag to code tag :)

Replies are listed 'Best First'.
Re: Strange one! Perl's or Apache's problem?!?
by Abigail-II (Bishop) on Feb 11, 2004 at 13:08 UTC
    @files = <../data/texts/*.txt>;
    This assumes the current working directory is appropriate. Most likely, when run as a CGI process, the current working directory is quite different from when you run it from the command line.

    Abigail

user error (your fault)
by Anonymous Monk on Feb 11, 2004 at 13:19 UTC
Re: Strange one! Perl's or Apache's problem?!?
by Anonymous Monk on Feb 11, 2004 at 13:13 UTC

    Whose fault is it? Perl's? Apache's?

    More likely, PEBCAK

Re: Strange one! Perl's or Apache's problem?!?
by davido (Cardinal) on Feb 13, 2004 at 02:05 UTC
    Nik, You just haven't dug into figuring out what everyone's been telling you in your previous thread on the same subject. You probably have a problem of the current working directory being different when the script is executed as a command line script versus as a CGI script. And because your glob is using relative pathnames, that fouls up your script. Have you attempted to understand what this means?

    You can be sure about it if you use Cwd; at the top of your script, and then print getcwd(), "<p>\n"; in the line of code right after your HTML header gets printed. This will let you to prove to yourself (as we've been suggesting) that the script is executing via CGI from a different CWD, thus fouling up your paths.


    Dave

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Strange one! Perl's or Apache's problem?!?
by nite_man (Deacon) on Feb 11, 2004 at 13:44 UTC

    Maybe file, which you tried send to the browser, is very huge? In my opinion, it is not good practic to load whole file to the array. Much better print line by line or use Tie::File - a Perl module for access to the file via array.

    Also, I suggest you to look at apache error log for more detailes and HTTP headers (you can use MozillaFirefox with special extension 'Live HTTP headers') to be sure that all HTTP headers are correct.

    ~ Schiller

    A reply falls below the community's threshold of quality. You may see it by logging in.