You're kind of getting off into the weeds now and there's probably not going to be an off the shelf module to do what you're wanting. The (naïve, obvious) solution would be to round trip things through a shell, but that's going to have security implications.

use feature qw( say ); use IPC::Run qw( run ); my $path = q{/a/b/c/$USER}; my $output = q{}; run( ['/bin/bash', '-c', qq{echo -n "$path"}, ], q{>}, \$output ); say qq{Output: $output};

The safer alternative is going to be walking over your strings and using something like s{\$(?: \{? (\S+) \}? )}{$ENV{$1} // qq{UNDEF:$1}}xge; to expand things yourself.

Edit: Obviously that's an imprecise regexp and to be more bulletproof you'd want to use Regexp::Common and be fancier pulling any curly wrapped bit(s) out with something like qr/\$ ($RE{balanced}{-parens=>q{{}}}) / and then working with that instead.

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


In reply to Re: rel2abs of a path with env by Fletch
in thread rel2abs of a path with env by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.