Tuesday, November 8, 2011

How can we access environmenttal variables in Perl?

Perl provides access to environment variables via the global %ENV hash. However, if using the Env module, it will create global scalars for all the environment variables.

use Env; print "$USER uses $SHELL";
If required to get only a few selected variables then it can be done like:
 
use Env qw[@PATH $USER]; print "$USER's path is @PATH";

No comments :