Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: rel2abs of a path with env

by ovedpo15 (Pilgrim)
on Jun 07, 2021 at 14:27 UTC ( [id://11133622]=note: print w/replies, xml ) Need Help??


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

Yes that's exactly what I did and it didn't resolve the env. The output of path("/a/b/c/$ENV{USER}")->absolute for me is /a/b/c/$ENV{USER}. Using Perl 5.26.1.
Edit: I misread. Sorry. Why did you replace /a/b/c/${USER} with /a/b/c/$ENV{USER}?

Replies are listed 'Best First'.
Re^3: rel2abs of a path with env
by parv (Parson) on Jun 07, 2021 at 21:37 UTC

    All worked here (FreeBSD 13, Perl 5.32, Path::Tiny 0.118) ...

    # perl -Mstrict -Mwarnings -MPath::Tiny -E \ 'say join qq[\n], map path( $_ )->absolute(), q[~/tmp], q[~tester/tmp], qq[/tmp/$ENV{USER}] ' /home/parv/tmp /home/tester/tmp /tmp/parv
Re^3: rel2abs of a path with env
by marinersk (Priest) on Jun 07, 2021 at 14:40 UTC

    Very odd. Thinking to step ouside of Linux, I tested this on Windows. It appears to have worked correctly for me as well.


    SKMDSK06::T:\>perl -V | findstr uname uname='Win32 strawberry-perl 5.32.0.1 #1 Sun Aug 2 19:46:04 2020 +x64'


    SKMDSK06::T:\>set user USERDOMAIN=SKMDSK06 USERDOMAIN_ROAMINGPROFILE=SKMDSK06 USERNAME=Steve USERPROFILE=C:\Users\Steve


    SKMDSK06::T:\>type test01.pl use strict; use Path::Tiny; my $path = path("/a/b/c/$ENV{USER}")->absolute; print "$path\n";


    SKMDSK06::T:\>perl test01.pl T:/a/b/c SKMDSK06::T:\>


    Not sure that this helps any, but there it is.

Re^3: rel2abs of a path with env
by Anonymous Monk on Jun 07, 2021 at 16:49 UTC

    Perl is not bash, and has different interpolation syntax. If you want to interpolate the value of an environment variable into a string in Perl, you say $ENV{USER}, not $USER.

    As to why you got a literal /a/b/c/$ENV{USER}, are you sure you used "/a/b/c/$ENV{USER}" and not '/a/b/c/$ENV{USER}'? The single quotes do not interpolate.

Re^3: rel2abs of a path with env
by ikegami (Patriarch) on Jun 09, 2021 at 05:55 UTC

    Because env vars are accessed using $ENV{USER}, and there presumably no var named $USER in your program.

    Seeking work! You can reach me at ikegami@adaelis.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-25 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found