Home > Archive > PERL Beginners > February 2007 > Home directory
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Daniel Kasak 2007-02-25, 9:58 pm |
| Hi all.
How do I, inside Perl, get the path of the home directory?
I assume if I can do this, it will only work under Linux / Unix?
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak@nusconsulting.com.au
website: http://www.nusconsulting.com.au
| |
| John W. Krahn 2007-02-25, 9:58 pm |
| Daniel Kasak wrote:
> Hi all.
Hello,
> How do I, inside Perl, get the path of the home directory?
> I assume if I can do this, it will only work under Linux / Unix?
$ perl -le'print( ( getpwuid $< )[ -2 ] )'
/home/john
$ perl -le'print $ENV{ HOME }'
/home/john
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
| |
| Tom Phoenix 2007-02-25, 9:58 pm |
| On 2/25/07, Daniel Kasak <dkasak@nusconsulting.com.au> wrote:
> How do I, inside Perl, get the path of the home directory?
my $user_home_dir = $ENV{HOME} || (getpwuid($< ))[7]; # maybe?
You could also try chdir with no arguments and see where it takes you.
> I assume if I can do this, it will only work under Linux / Unix?
Systems that run Perl may not have the concept a home directory, but
you could default to the current working directory, say, if $ENV{HOME}
is unset.
Hope this helps!
--Tom Phoenix
Stonehenge Perl Training
| |
| Thomas Yan 2007-02-25, 9:58 pm |
| Hello,
> Hi all.
>
> How do I, inside Perl, get the path of the home directory?
> I assume if I can do this, it will only work under Linux / Unix?
Under windows you can use
print $ENV{USERPROFILE}
to get the home directory.
such as: C:\Documents and Settings\yantao
USERPROFILE is the environment variable.
> --
> Daniel Kasak
> IT Developer
> NUS Consulting Group
> Level 5, 77 Pacific Highway
> North Sydney, NSW, Australia 2060
> T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
> email: dkasak@nusconsulting.com.au
> website: http://www.nusconsulting.com.au
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
| |
| Igor Sutton Lopes 2007-02-26, 7:59 am |
| Hi,
On 2007/02/26, at 02:26, Thomas Yan wrote:
> Hello,
>
>
> Under windows you can use print $ENV
> {USERPROFILE} to get the home directory. such
> as: C:\Documents and Settings\yantao
> USERPROFILE is the environment variable.
>
You can also use the File::HomeDir module, that implements the
abstraction for those operational systems.
HTH!
--
Igor Sutton Lopes <igor.sutton@segula.pt>
| |
| loveperl6@aol.com 2007-02-26, 7:00 pm |
| Or depending on when you need this found. you might able to use.
chomp($home=`pwd`);
-----Original Message-----
From: igor.sutton@gmail.com
To: yantao@neusoft.com
Cc: dkasak@nusconsulting.com.au; beginners@perl.org
Sent: Mon, 26 Feb 2007 4:50 AM
Subject: Re: Home directory
Hi,
On 2007/02/26, at 02:26, Thomas Yan wrote:
Hello,
Hi all.
How do I, inside Perl, get the path of the home directory?
I assume if I can do this, it will only work under Linux / Unix?
Under windows you can use print $ENV{USERPROFILE} to get the home directory. such as: C:\Documents and Settings\yantao
USERPROFILE is the environment variable.
You can also use the File::HomeDir module, that implements the abstraction for those operational systems.
HTH!
--
Igor Sutton Lopes <igor.sutton@segula.pt>
=
________________________________________
________________________________
Check out the new AOL. Most comprehensive set of free safety and security tools, free access to millions of high-quality videos from across the web, free AOL Mail and more.
| |
| Ken Foskey 2007-02-26, 7:00 pm |
| On Mon, 2007-02-26 at 11:40 -0500, loveperl6@aol.com wrote:
> Or depending on when you need this found. you might able to use.
>
> chomp($home=`pwd`);
This is so unlikely to work I would never do this. I start scripts in
my home directory < 10% of the time.
--
Ken Foskey
FOSS developer
|
|
|
|
|