.env is not standard in any traditional shell I am aware of, but that set is limited to:
sh/
bash and
csh/
tcsh.
If the format of that file indicates a standard shell "rc" type file with (for Bourne style), then I would not attempt to read it in your Perl program since it can contain anything the shell supports. The following is deceptive because it's just a basic shell script:
VAR="some value"
export VAR
Rather, source it before your Perl program is invoked. This will do the right thing, and be available in %ENV.
If it's an ini format, use something like Config::Tiny - or whatever module is appropriate for the serialization format. Because that's all it is; don't invent your own. you would not do this for JSON, YAML, or XML - I hope :)
A few notes about understanding the %ENV in your Perl program; and assuming we're dealing strictly within the same process space on the same machine, etc:
- your entire environment is available to a perl process under which it is invoked via %ENV
- modifying %ENV in your program is respected by the current process and all child processes created by it (including via system, fork etc
- child processes can affect their own env and that of their
ancestors descendants, but not of their parent - even if you export - this means when your program returns from running to your interactive shell (e.g.,) the environment will not have changed based on anything your program did (and it can't)
- best practice is to localize %ENV if you plan on mucking with it in your perl program, e.g., local %ENV = %ENV; - this is so you can control the scope of the changes in the same process using Perl's built in scoping; in other words, it allows you to "go back" to the original %ENV or at least only affect it in very precise parts of your program; as noted above, it is not needed to "protect" your interactive shell's environment once the program has returned
The last thing I'll end with is, don't parse files that are meant to affect your shell environment in Perl. Use the shell to source it; then invoke your program.
HTH
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.