Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > $ENV HOME on windows

Reply
Thread Tools

$ENV HOME on windows

 
 
Bob
Guest
Posts: n/a
 
      04-22-2007
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};

 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      04-22-2007
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.

--
Affijn, Ruud

"Gewoon is een tijger."

 
Reply With Quote
 
 
 
 
Peter Scott
Guest
Posts: n/a
 
      04-23-2007
On Sun, 22 Apr 2007 09:19:35 -0700, Bob wrote:
> 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?


See
http://search.cpan.org/~rkobes/File-...meDir/Win32.pm

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      04-25-2007
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Dr.Ruud
<rvtol+>], who wrote in article <>:

> 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
 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      04-26-2007
Petr Vileta <> wrote in comp.lang.perl.misc:
> "Ilya Zakharevich" <nospam-> píše v diskusním příspěvku
> news:f0opmc$27r$...
> > 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


One of these should be $ENV{HOMEDRIVE}

> > would remove at least 10-20% of porting problems...
> >

> 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
 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      04-26-2007
[A complimentary Cc of this posting was sent to
A. Sinan Unur
<>], who wrote in article <Xns991E5FEC1439Casu1cornelledu@127.0.0.1>:
> >> > 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


> > One of these should be $ENV{HOMEDRIVE}


Yeah, thanks.

> >> > would remove at least 10-20% of porting problems...


> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XP home SP2 cannot view/access my XP home SP1 or my Win2K machines =?Utf-8?B?SmFtaW5h?= Wireless Networking 3 02-15-2006 02:18 AM
How To Connect Your PC to Your Home Stereo or Home Theater Silverstrand Front Page News 0 12-08-2005 01:29 PM
Home Network - XP Home Edition and Windows 2000 =?Utf-8?B?UEFS?= Wireless Networking 1 12-30-2004 09:40 PM
Set up home a home or small office network!!!! Chris Jardine Computer Support 2 04-06-2004 02:28 AM
When I open Internet Explorer, along with my home page a pop page pops up, I have changed home page but that doesnt work Phil Computer Support 7 03-04-2004 12:22 AM



Advertisments