0

The code is supposed to read a file in perl but is supposed to be modified with CGI. I have looked over several tutorials, and think it is the file path, but cannot get it to work. Any ideas? I'm newer to CGI and perl. Trying to run it through html.

#!/usr/bin/perl
use warnings;
use strict;

my $filename = '/home/cisstudent/test.txt';
open(FH, '<', $filename) or die $!;
print("File $filename opened successfully!\n");
close(FH);
brian d foy
  • 129,424
  • 31
  • 207
  • 592
krappold
  • 17
  • 1
  • 7
  • Please move your files under html directory and change the permission of the file. – mkHun Apr 15 '21 at 06:57
  • https://stackoverflow.com/questions/25714341/how-can-i-read-files-outside-the-cgi-bin-folder – mkHun Apr 15 '21 at 07:04
  • Is the file really in the root of the `/home` directory? Usually it'd be under `/home/username`. Also, are you getting any errors printed? – stevieb Apr 15 '21 at 14:41

1 Answers1

0

The first line of your posted code is incorrect - it should be #!/usr/bin/perl - /usr, not /user.

If that doesn't fix the script (or if it's just a typo in the post, rather than in your actual code), then you'll need to provide additional details, such as how you're running the script and the error message received when you attempt to run it.

Dave Sherohman
  • 45,363
  • 14
  • 64
  • 102
  • I have the test file in the html directory, and have corrected the filename, but am still getting an error when running the cgi file of internal server error. – krappold Apr 15 '21 at 17:25
  • @krappold OK, in that case, "_you'll need to provide additional details, such as how you're running the script and the error message received when you attempt to run it._" If your web server is reporting "Internal Server Error", then the actual error message can be found in the error log file. – Dave Sherohman Apr 16 '21 at 07:50