An alternative to $ENV{HOME} is (getpwuid $>)[7]. I don't know which might be better, if one is. If you're in a shell environment and $HOME either doesn't exist or is stripped, then that could be an issue. For example, I do this a lot:
my $HOME = (getpwuid $>)[7];
my $ssh_dir = qq{$HOME/.ssh};
(update)
I wanted to add, that getpwuid is probably more reliable when you're doing stuff with setuid; in the example above, $> is the effective user; $< being the real user. I don't think invoking it updates $ENV in any way, like su - OTHER_USER would directly in the shell before invoking the script in question (certainly doing this in the script would not effect the parent process's %ENV at all). perlsec looks informative regarding this. But it just depends on what OP is doing. If there is no reason or need to use setuid (or setguid), then $ENV{HOME} is probably fine.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|