Anil
Anil

Reputation: 3992

How to check the perl environment variables used in the script before executing?

How to know that the environment used in the script is the same that the program will see when it runs?. Perl stores the environment in %ENV to my knowledge.

i am trying to use the code which is mentioned below in order to know the variables.

    require Data::Dumper;
    print STDERR Data::Dumper::Dumper( \%ENV );

Is there any procudure to check the env variables used before the script starts executing?

Upvotes: 2

Views: 1756

Answers (2)

flesk
flesk

Reputation: 7579

Not sure what you're getting at, but you can put your code inside a BEGIN block to see what your environment variables are before any modules you use are loaded.

BEGIN {
    require Data::Dumper;
    print STDERR Data::Dumper::Dumper( \%ENV );
}

Upvotes: 4

Linus Kleen
Linus Kleen

Reputation: 34632

The contents of %ENV are inherited to any process you execute from a perl script.

If you're concerned that a child process reads sensitive information from your environment, give it a clean one before running it:

do {
    local %ENV;
    $ENV{PATH} = '/usr/bin';
    system './another-binary';
};

Upvotes: 4

Related Questions