in reply to Re: how to expand home directory ~
in thread how to expand home directory ~

Probably the same thing as File::Path::Expand

MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
** The third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^3: how to expand home directory ~
by derby (Abbot) on Jun 02, 2005 at 13:14 UTC

    They're pretty close but it looks like File::Path::Expand chokes on the simple cases of ~name and just ~. Not that the perlfaq regex is any better, it chokes when $ENV{HOME} and $ENV{LOGDIR} are not set. A better approach would be something along the lines of:

    $file =~ s{ ^ ~ # find a leading tilde ( # save this in $1 [^/] # a non-slash character * # repeated 0 or more times (0 means me) ) }{ $1 ? (getpwnam($1))[7] : (getpwuid($<))[7] }ex;
    -derby