sanku has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, the following program is running in command prompt but it's not running in apache web server can any one give me some idea's of it.
#!/usr/bin/perl print "Content-type:text/html\n\n"; use warnings; use strict; #use File::Basename; opendir(DIR,"/root/sample/directory/") or die $!; my @dir=readdir(DIR); close (DIR); foreach my $directory(@dir){ if($directory =~/^\w/){ print $directory; } }
Thanks in advance.

Replies are listed 'Best First'.
Re: this program is not running in apache web server
by lamp (Chaplain) on Oct 30, 2008 at 06:21 UTC
    For debugging, check your web server's error log.
Re: this program is not running in apache web server
by Gangabass (Vicar) on Oct 30, 2008 at 06:28 UTC

    I'm sure your webserver process have no rights to access /root folder.

      hi Gangabass, Could you please tell me how to give access permission for the root folder as my webserver process have no rights to access /root folder. Thank you
        Could you please tell me how to give access permission for the root folder as my webserver process have no rights to access /root folder.

        Don't. On most Unix systems there's dedicated place for stuff like that, and it's /var/www/ or /srv/www/. Use that instead of fiddling with you root user's home directory.

Re: this program is not running in apache web server
by GrandFather (Saint) on Oct 30, 2008 at 06:25 UTC

    What do you see in the server logs?


    Perl reduces RSI - it saves typing
Re: this program is not running in apache web server
by quester (Vicar) on Oct 30, 2008 at 06:31 UTC
    You should discover that the opendir call is failing. Unless the security of your web server is horribly messed up, the web server will not have any access to the /root directory. You might want to make a separate top level directory and give the web server's account (usually apache or httpd) the appropriate access to it.