我是新來的Perl及其在CGI中的使用。我一直有這個錯誤500幾個小時,仍然不知道錯誤(s)在哪裏。該腳本放置在Apache服務器的相應/usr/lib/cgi-bin
文件夾中。它然後通過這個簡單的HTML表單稱爲:找不到錯誤500的原因 - Perl
<FORM action="http://localhost/cgi-bin/sensors.cgi" method="POST">
Sample period: <input type="text" name="sample_period"> <br>
<input type="submit" value="Submit">
</FORM>
由於FAS,因爲我知道,一個錯誤500當有不正當的上傳或在腳本中的錯誤出現。但我已經測試上傳其他文件,並沒有問題。這就是爲什麼我相信代碼中可能存在錯誤。這是Perl腳本:
#!/usr/bin/perl
use IO::Handle;
# Open the output file that contains the sensors' readings. It's open in write mode, and
# empties the content of the file on each opening.
open (my $readings, ">", "sensors_outputs.txt") || die "Couldn't open the output file.\n";
# Defines the physical magnitudes and sets each one a random value.
my $temp = rand 30;
my $hum = rand 100;
my $pres = 1000 + rand(1010 - 1000);
my $speed = rand 100;
for(;;) {
# Writes in the file-handler's file the values of the physical magnitudes.
print $readings "$temp\n$hum\n$pres\n$speed";
# Flush the object so as not to open and close the file each time a new set of
# values is generated.
$readings->autoflush;
# Move the file-handler to the beggining of the file.
seek($readings, 0, SEEK_SET);
# Generate new a new data set.
$temp = rand 10;
$hum = rand 100;
$pres = 1000 + rand 10;
$speed = rand 100;
sleep 1;
}
close $readings || die "$readings: $!";
如果需要,請不要猶豫,問我更多的上下文。在此先感謝
這些天,Perl社區已經基本上從CGI轉移到了[PSGI/Plack](http://plackperl.org/)。 – Quentin
[嚴格使用,使用警告](http://perlmaven.com/always-use-strict-and-use-warnings) – Quentin
@Quentin:「離開CGI」是一回事,但不是每個人都會轉向正義一個框架... – stevieb