$ENV HOME on windows

Discussion in 'Perl Misc' started by Bob, Apr 22, 2007.

  1. Bob

    Bob Guest

    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};
     
    Bob, Apr 22, 2007
    #1
    1. Advertising

  2. Bob

    Dr.Ruud Guest

    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."
     
    Dr.Ruud, Apr 22, 2007
    #2
    1. Advertising

  3. Bob

    Peter Scott Guest

    Peter Scott, Apr 23, 2007
    #3
  4. [A complimentary Cc of this posting was NOT [per weedlist] sent to
    Dr.Ruud
    <>], 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
     
    Ilya Zakharevich, Apr 26, 2007
    #4
  5. Bob

    -berlin.de Guest

    Petr Vileta <> wrote in comp.lang.perl.misc:
    > "Ilya Zakharevich" <> 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
     
    -berlin.de, Apr 26, 2007
    #5
  6. [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
     
    Ilya Zakharevich, Apr 26, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ankit Mehta
    Replies:
    1
    Views:
    1,448
    Simon Brooke
    Sep 29, 2006
  2. nancyflorida
    Replies:
    0
    Views:
    342
    nancyflorida
    Nov 12, 2007
  3. nancyflorida
    Replies:
    0
    Views:
    325
    nancyflorida
    Nov 12, 2007
  4. * Its my Pleasure *
    Replies:
    0
    Views:
    386
    * Its my Pleasure *
    Feb 20, 2008
  5. TDR
    Replies:
    3
    Views:
    181
    Daniel Berger
    Aug 31, 2007
Loading...

Share This Page