Creating a registry of environment variables

I want a registry of environment variables. If I see someone using one, I want to know what it does and what code or programs uses that. Or, given a program, what are all the variables that might affect it?

Rather than do the whole thing, I let myself do part of the first bit. I crawled all of my installed modules to pull out the keys used with %ENV. My solution (here's the gist) does some dumb matching then passes the result to PPI. It's probably another easy step to make PPI find uses of %ENV too (and skip all the mentions in the docs).

Some modules define their own variables, and some of those are even documented. Many use variables that they expect you to know about already, such as $ENV{HOME}.

From just the stuff I had installed (about 20 different perls), here are the most frequent, with their count:

TERM: 511
PAGER: 631
PWD: 1919
PATH: 1997
PERL5LIB: 2187
HOME: 2325

The next time I have a chance to work on this, I'll get into into some sort of data store along with the module that uses each. The harder task to is to identify the modules that create the variables. I suppose that I could discount the ones that show up in several different modules.

1 Comment

Tangentially this is how I make sure that having some variable set won't prevent a test suite from passing:

And the result is:


Leave a comment

About brian d foy

user-pic I'm the author of Mastering Perl, and the co-author of Learning Perl (6th Edition), Intermediate Perl, Programming Perl (4th Edition) and Effective Perl Programming (2nd Edition).