in reply to How to convert unix ~path (tilde) to full path

If the program is not running as the user, $ENV{HOME} won't work. getpwnam returns a list with home directory at index seven.

After Compline,
Zaxo

  • Comment on Re: How to convert unix ~path (tilde) to full path

Replies are listed 'Best First'.
Re: Re: How to convert unix ~path (tilde) to full path
by Rich36 (Chaplain) on Apr 05, 2002 at 17:23 UTC

    Zaxo speaks the truth... Adapted from The Perl Cookbook (pg.231)...

    my $file = '~rich36/perl/makeperl'; $file =~ s{ ^ ~ ( [^/]* ) } { $1 ? (getpwnam($1))[7] : ( $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($>))[7] ) }ex; print "$file"; __DATA__ /home/users/rich36/perl/makeperl

    Rich36
    There's more than one way to screw it up...