7.3. Expanding Tildes in FilenamesProblemYou want to open filenames like ~username/blah, but SolutionExpand the filename manually with a substitution: $filename =~ s{ ^ ~ ( [^/]* ) }
{ $1
? (getpwnam($1))[7]
: ( $ENV{HOME} || $ENV{LOGDIR}
|| (getpwuid($>))[7]
)
}ex;DiscussionThe uses of tilde that we want to catch are: ~user
~user/blah
~
~/blahIf no name follows the This substitution uses See AlsoYour system's getpwnam (2) manpage; the |