我是新来的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