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;
|