"be consistent" | |
PerlMonks |
Re: .env loading the dot env file?by perlfan (Vicar) |
on Mar 28, 2021 at 18:32 UTC ( [id://11130519]=note: print w/replies, xml ) | Need Help?? |
.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:
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:
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
In Section
Seekers of Perl Wisdom
|
|