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

When viewing env variables through a CGI script, I would like to see the variables for the owner of the script itself. My first thought is that those variables are outside the CGI scope. How could I get to them?
  • Comment on How do I get the environment variables for the owner of a CGI script?

Replies are listed 'Best First'.
Re: How do I get the environment variables for the owner of a CGI script?
by diotalevi (Canon) on Oct 28, 2004 at 21:48 UTC
    Environment variables emanate from the user currently running the program. If you want to make a snapshot of a particular user's environment variables, save them somewhere when that user runs your code.
      I was thinking of getting the username of the owner and then logging in and doing a printenv - all from within the CGI script, but this seems exceedingly silly.
        Yes, but that's what you have to do.
Re: How do I get the environment variables for the owner of a CGI script?
by Joost (Canon) on Oct 28, 2004 at 21:59 UTC
Re: How do I get the environment variables for the owner of a CGI script?
by tilly (Archbishop) on Oct 29, 2004 at 01:23 UTC
Re: How do I get the environment variables for the owner of a CGI script?
by Happy-the-monk (Canon) on Oct 28, 2004 at 21:50 UTC

    Unix: be the owner of the script, type "env". That will show you the environment.

    Perl has a hash called %ENV that holds the same... but in case of CGI, that should be either the environment of the webserver process or just the CGI environment from CGI.pm. Look it up in the documentation of CGI.pm.

    Update: ...which doesn't even mention it, sadly. You can still print in a html table

    foreach my $key ( sort keys %ENV ) { print( Tr( td( $key ), td( $ENV{$key} ) ) ) }

    Cheers, Sören

      I appreciate every response, but you don't understand my question.
Re: How do I get the environment variables for the owner of a CGI script?
by ercparker (Hermit) on Oct 29, 2004 at 04:09 UTC
    to get the real username of the running perl script you could do this:
    my $owner = getpwuid($<);
    I apologize if I misunderstood you question.