Env::Dot(3pm)
π Env::Dot π
okay bestie, welcome to Env::Dot, from the User Contributed Perl Documentation family. she reads your environment variables straight out of a .env file and honestly? she's that girl. π
β¨ NAME β¨
Env::Dot β reads environment variables from a .env file. yes that's it, that's the whole thing, and it's iconic. π
β¨ VERSION β¨
this is version 0.022 π
β¨ SYNOPSIS β¨
bestie. the synopsis is literally empty. nothing there. the void. π«₯
do not panic tho β all the juicy usage examples are living their best life down in STATUS. go look there. β
β¨ DESCRIPTION β¨
she gives you more flexibility in how you manage and use your .env file. that's the whole vibe. πΈ
β¨ STATUS β¨
heads up, queen: this module is currently being developed, so changes in the API are possible β though, like, not likely. π
# If your dotenv file is `.env`:
use Env::Dot;
# or
use Env::Dot 'read';
print $ENV{'VAR_DEFINED_IN_DOTENV_FILE'};
# If you have a dotenv file in a different filepath:
use Env::Dot read => {
dotenv_file => '/other/path/my_environment.env',
};
# When you absolutely require `.env` file:
use Env::Dot read => {
required => 1,
};
Attn. β οΈ Existing environment variables always take precedence to dotenv variables! a dotenv variable (a variable from a file) does not overwrite an existing environment variable. this is by design β because a dotenv file is there to augment the environment, not to replace it. periodt.
which means you can override a variable in a .env file by creating its counterpart in the environment. for instance:
unset VAR
echo "VAR='Good value'" >> .env
perl -e 'use Env::Dot; print "VAR:$ENV{VAR}\n";'
# VAR:Good value
VAR='Better value'; export VAR
perl -e 'use Env::Dot; print "VAR:$ENV{VAR}\n";'
# VAR:Better value
π Features π
- If no .env file is present, then do nothing β by default, Env::Dot will do nothing if there is no
.envfile. you can also configure Env::Dot to break execution if there is no.envfile in the current working directory. no cap. π
use Env::Dot read => {
required => 1,
};
- Specify other dotenv files with path β if your
.envfile is located in another path, not the current working directory, you can use the environment variableENVDOT_FILEPATHSto tell where your dotenv file is located. you can specify several file paths; just separate them by:. π₯
Env::Dot will load the files in the reverse order, starting from the last. this is the same ordering as used in PATH variable: the first overrules the following ones β that is, when reading from the last path to the first path, if the same variable is present in more than one file, the later one replaces the one already read.
Attn. if you are using Windows, separate the paths by ;! πͺ
for example, if you have the following directory structure:
project-root
| .env
+ - sub-project
| .env
and you specify ENVDOT_FILEPATHS=project-root/sub-project/.env:project-root/.env, then the variables in file project-root/.env will get replaced by the more specific variables in project-root/sub-project/.env.
in Windows, this would be ENVDOT_FILEPATHS=project-root\sub-project\.env;project-root\.env
N.B. The ordering has changed in version 0.0.9. π
- Support different types of .env files β Unix Shell
sourcecommand compatible dotenv files use double or single quotation marks ("or') to define a variable which has spaces. but, for instance, Docker compatible.envfiles do not use quotation marks. the variable's value begins with the=sign and ends with linefeed.
you can specify in the dotenv file itself β by using meta commands β which type of file it is. π
- Use executable envdot to bring the variables into your shell β the executable is distributed together with the Env::Dot package. it is in the directory
script. β¨
The executable script/envdot is not Windows compatible!
a Windows (MS Command and Powershell compatible) version, script\envdot.bat, is possible in a future release. please contact the author if you are interested in it. π«Ά
eval "$(envdot)"
N.B. if your .env file(s) contain variables which need interpolating β for example, to combine their value from other variables or execute a command to produce their value β you have to use the envdot program. Env::Dot does not do any interpolating. it cannot, because that would involve running the variable in the shell context. π
π¦ DotEnv File Meta Commands π¦
the var: commands affect only the subsequent variable definition. if there is another envdot command, the second overwrites the first and default values are applied again. π
read:from_parentβ by setting this option to true, Env::Dot orenvdotcommand will search for.envfiles in the file system tree upwards. it will load the first.envfile it finds from the current directory upwards to root. β¬οΈ
using read:from_parent will only find and read one .env file in a parent directory. if you want to chain the .env files, they all must set read:from_parent β except the top one.
this functionality can be useful in situations where you have parallel projects which share common environment variables in one .env file in a parent directory. ποΈ
if there is no parent .env file, Env::Dot will break execution and give an error. π΅
by default this setting is off.
read:allow_missing_parentβ when using optionread:from_parent, if the parent.envfile does not exist, by default Env::Dot will emit an error and break execution. in some situations, it might be normal that a parent.envfile could be missing. turn on optionread:allow_missing_parentif you do not want an error in that case. π
by default this setting is off.
file:typeβ changes how Env::Dot reads lines below from this command. default is:
# envdot (file:type=shell)
VAR="value"
other possible value of file:type is:
# envdot (file:type=plain)
VAR=My var value
var:allow_interpolateβ by default, when writing variable definitions for the shell, every variable is treated as static and surrounded with single quotation marks'in Unix shell which means shell will read the variable content as is. by setting this to1ortrue, you allow shell to interpolate. this meta command is only useful when runningenvdotcommand to create variable definitions forevalcommand to read. β
# envdot (var:allow_interpolate)
DYNAMIC_VAR="$(pwd)/${ANOTHER_VAR}"
β¨ DEPENDENCIES β¨
No external dependencies outside Perl's standard distribution. she's low maintenance, we love that for her. π
β¨ FUNCTIONS β¨
No functions exported to the calling namespace. clean. minimal. no clutter. π
πΈ load_vars πΈ
loads variables from .env file or files in environment variable ENVDOT_FILEPATHS.
β¨ SEE ALSO β¨
- Env::Assert will verify that you certainly have those environmental variables you need. it also has an executable which can, for example, perform the check in the beginning of a docker container run. π³
- Dotenv and ENV::Util <https://metacpan.org/pod/ENV::Util> are packages which also implement functionality to use
.envfiles in Perl. - Config::ENV and Config::Layered::Source::ENV provide other means to configure application with the help of environment variables. π οΈ
- shdotenv <https://github.com/ko1nksm/shdotenv> is a project to provide dotenv for shells with support for POSIX-compliant and multiple
.envfile syntax. π
β¨ AUTHOR β¨
Mikko Koivunalho <mikkoi@cpan.org> π
β¨ COPYRIGHT AND LICENSE β¨
this software is copyright (c) 2023 by Mikko Koivunalho.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π«Ά
okay that's the whole page bestie, you ate that. π this was Env::Dot version 0.022, running on perl v5.40.1, and this page is dated 2026-05-09. go forth and dotenv, queen. πβ¨π
π¦ where this page comes from
- ubuntu stonking: env-dot 0.022-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms