
Jasmine
Administrator
Jan 26, 2001, 10:16 AM
Post #1 of 1
(3231 views)
|
How can I translate tildes (~) in a filename?
|
Can't Post
|
|
(From the Perl FAQ) How can I translate tildes (~) in a filename? Use the <> (glob()) operator, documented in the perlfunc manpage. This requires that you have a shell installed that groks tildes, meaning csh or tcsh or (some versions of) ksh, and thus may have portability problems. The Glob::KGlob module (available from CPAN) gives more portable glob functionality. Within Perl, you may use this directly: $filename =~ 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] : ( $ENV{HOME} || $ENV{LOGDIR} ) }ex;
|