in reply to Re: rel2abs of a path with env
in thread rel2abs of a path with env

Thanks. I wrote the following regex:
sub resolve_env_in_path { my ($path) = @_; $path =~ s/\$\{(\w+)\}/$ENV{$1}/g; $path =~ s/\$(\w+)/$ENV{$1}/g; return $path; }
What do you think?

Replies are listed 'Best First'.
Re^3: rel2abs of a path with env
by Fletch (Bishop) on Jun 07, 2021 at 14:42 UTC

    One thing your version silently strips out any undefined variables; using the /e modifier lets you have an expression rather than just a quoted string so you can do a bit of logic on the RHS of the substitution ...{ $ENV{$1} // qq{MISSING:$1} }e (so you get an indication what's missing).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.