$ENV HOME on windows

B

Bob

I apologise for the basic question, but I am using perl on windows for
the first time (after about 20 years using it on unix...) and the
problem does not make sense to me. Perl (active state) complaints that
the value is not initialized. Why in heaven?

#!/usr/bin/perl -w
use strict;
use diagnostics;
print $ENV{HOME};
 
D

Dr.Ruud

Bob schreef:
I apologise for the basic question, but I am using perl on windows for
the first time (after about 20 years using it on unix...) and the
problem does not make sense to me. Perl (active state) complaints that
the value is not initialized. Why in heaven?

#!/usr/bin/perl -w
use strict;
use diagnostics;
print $ENV{HOME};

Do a `set` in a CMD shell console window, or use perl:
perl -wle "print qq{$_=$ENV{$_}} for sort keys %ENV"
(which will show the keys in allcaps)
and you'll see something like

HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Username


The concatenation can be used as HOME:

BEGIN {
if ( substr ( $^O, 0, 5 ) eq q{MSWin} ) {
if ( $ENV{HOME} ) {
# leave as is
}
elsif ( $ENV{USERPROFILE} ) {
$ENV{HOME} = $ENV{USERPROFILE};
}
elsif ( $ENV{HOMEDRIVE} and $ENV{HOMEPATH} ) {
$ENV{HOME} = $ENV{HOMEDRIVE} . $SENV{HOMEPATH};
}
else {
$ENV{HOME} = '.';
} } }

There are also modules on the cpan that do something alike.
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was NOT [per weedlist] sent to
Dr.Ruud
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Username

What puzzles me deep is why Perl on Windows is not faking $ENV{HOME}
if $ENV{HOMEPATH} and $ENV{HOMEPATH} are both present... I think this
would remove at least 10-20% of porting problems...

Yours,
Ilya
 
A

anno4000

One of these should be $ENV{HOMEDRIVE}
From which hell get you HOME variable? :)

The suggestion is for Perl to *fake* it in %ENV, deriving the value
from $ENV{HOMEDRIVE} and $ENV{HOMEPATH}. The system environment
doesn't have to have HOME for that.

Anno
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
A. Sinan Unur

Yeah, thanks.
Which might be a problem for those of us who create a D:\Home and move
users' 'My Documents' folders to directories under D:\Home\<userid> and
add a HOME variable to each user's environment. I am assuming such
problems can be avoided by checking for the existence of of $ENV{HOME}
before faking it.

Hmm, I thought that this would be clear without saying... Sorry!
However, this means that the check and the decision as
to whether to fake $ENV{HOME} should not be done at install time but
each time a script is run.

Each time the interpreter starts.

Hope this helps,
Ilya
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top