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

It's a little redundant to see if the string begins with a ~ and then remove it, when s/^~// will only return true if it replaced anything.

Also, it might be nice to fallback to the home directory returned by getpwuid just in case $ENV{'HOME'} isn't set ...

use File::Spec; my $filename = '~/public_html/'; if ( $filename =~ s<^~([^/]*)/></> ) { my $homedir = $1 ? (getpwnam($1))[7] # specified user : $ENV{'HOME'} || (getpwuid($<))[7] # ourselves or die "Where's your home?\n"; $filename = File::Spec->catfile($homedir, $filename); }

Update: Fixed to account for jeffenstein's observation.

    --k.


: