title: Can't find reason for error 500 - Perl
body: <p>I'm new to Perl and its use in CGI. I've been having this error 500 for some hours and still don't know where's the error(s). The script is placed in the corresponding <code>/usr/lib/cgi-bin</code> folder of the Apache server. It's then called by this simple HTML form:</p>
  
  <pre><code>&lt;FORM action="http://localhost/cgi-bin/sensors.cgi" method="POST"&gt;
  Sample period: &lt;input type="text" name="sample_period"&gt;  &lt;br&gt;
  &lt;input type="submit" value="Submit"&gt;
  &lt;/FORM&gt;
  </code></pre>
  
  <p>As fas as I know, an error 500 appears when there was an improper upload or a bug in the script. But I've tested uploading other files and had no problems with it. Thats why I believe there may be a bug in the code. This is the Perl script:</p>
  
  <pre><code>#!/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, "&gt;", "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-&gt;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: $!";
  </code></pre>
  
  <p>Don't hesitate to ask me for more context if needed. Thanks in advance</p>