Perl Server Script

Discussion in 'Division by Zero' started by TheRaiderNation, Jul 26, 2011.

  1. TheRaiderNation

    TheRaiderNation Spartan

    Joined:
    Nov 23, 2008
    Messages:
    171
    Likes Received:
    2
    Last played:
    NCAA Football 14 on PS3
    I've recently installed Apache Server 2.2 and the latest version of Perl on an old computer I had lying around. The server is running and connected to the internet and I can access files inside of /htdocs/ and run scripts from /cgi-bin/ no problem. The issue comes in when I'm trying to run a script that tries to read a file from the server.

    In other words a script that simply prints "Hello World" will work, but a script that tries to read in Hello World from a file and then print it out won't work.

    Here is the script I am using:
    Code:
    #!c:/per/bin/perl.exe
    ## Basic file reader
    
    $file = '../htdocs/helloworld.txt';
    open(INFO, $file);
    while(<INFO>)
    {
    	chomp;
    	print "$_\n";
    }
    close(INFO);
    
    If I try http://[server-ip]/cgi-bin/FileReader.pl I'll get a 500 Internal Server Error. However, execute it via cmd the script works and prints out the Hello World.

    Thanks in advance

    EDIT: So I update the script, it no longer attempts to read from a file, rather write to an existing file and create a new file. Odd thing is that I'm still getting a 500 Error, but the script seems to work, it creates a new file on the server and modifies the existing one. Any idea why I'm still getting the 500 error though?
  2. LocutusEstBorg

    LocutusEstBorg Contributor

    Joined:
    Sep 9, 2008
    Messages:
    1,876
    Likes Received:
    14
    Last played:
    Gears of War 2 on Xbox 360
    http://www.pageresource.com/cgirec/ptut14.htm

    While it's good to know Perl because only then will you truly understand HTTP, server side languages, and the web in general, Perl is an obsolete unproductive language.

    Learn the basics of executing server side code and outputting HTML results to the browser, and then move on to PHP with some frameworks or ASP.Net Web Forms or ASP.Net MVC. I suggest you first try out ASP.Net Web Forms to realize what a joke Perl really is in this age.
  3. TheRaiderNation

    TheRaiderNation Spartan

    Joined:
    Nov 23, 2008
    Messages:
    171
    Likes Received:
    2
    Last played:
    NCAA Football 14 on PS3
    You know, I kind of figured the same thing. But really the script is simple and doesn't require too much. So I just wrote it really quick in perl. Also, the link you mentioned is exactly what I'm doing. The script works apparently, and gives the proper results server side. But returns a 500 error to the client. I think I have an idea what's going on. I'll just have to look into it a little bit more.
  4. LocutusEstBorg

    LocutusEstBorg Contributor

    Joined:
    Sep 9, 2008
    Messages:
    1,876
    Likes Received:
    14
    Last played:
    Gears of War 2 on Xbox 360
  5. TheRaiderNation

    TheRaiderNation Spartan

    Joined:
    Nov 23, 2008
    Messages:
    171
    Likes Received:
    2
    Last played:
    NCAA Football 14 on PS3
    That's exactly what I was thinking (the not printing the correct headers part). Thanks for the nudge in the right direction though, I'll check my logs in the morning.

Share This Page