Subject: | Home Directory |
Date: | Thu, 12 Mar 2009 18:28:04 +0100 |
To: | bug-File-BaseDir [...] rt.cpan.org |
From: | David Raab <d.raab [...] angel.de> |
Hi,
we use a web application, and because of this $ENV{HOME} is never set.
But "File::BaseDir" uses this to read the home directory. If it is not
set it throws a warning. This is very annoying.
But the real problem is, that using $ENV{HOME} is not the correct way
to getting the home directory of the user. This environment variable can
be set
before loading the module to absolut anything. Even before Perl starts
we can
change the content of HOME. The correct way of reading the home directory
for the user (on Unix like machines) is to read it out from /etc/passwd.
Perl already have functions to read data from passwd. To read the home
directory of the currently logged in user we can write something like this:
Show quoted text
> my $home = (getpwuid($>))[7]
Using this instead of
Show quoted text> my $home = $ENV{HOME}
would be much nicer.
--
ANGEL Internet Services GmbH | Sitz der Gesellschaft: Köln
Vogelsanger Str. 105 50823 Köln | Handelsregister Köln HRB27723
T 0221 9440310 F 0221 9440318 | Geschäftsführer: Angel Santos
www.angel.de info@angel.de |