Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: File::Find::Rule Help Needed

by perlfan (Vicar)
on Apr 03, 2021 at 15:26 UTC ( #11130775=note: print w/replies, xml ) Need Help??


in reply to Re: File::Find::Rule Help Needed
in thread File::Find::Rule Help Needed

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11130775]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2022-05-17 23:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?