Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

How can I translate tildes (~) in a filename?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:23 UTC ( #654=perlfaq nodetype: print w/replies, xml ) Need Help??

Current Perl documentation can be found at

Here is our local, out-dated (pre-5.6) version:

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)
              ? (getpwnam($1))[7]
              : ( $ENV{HOME} || $ENV{LOGDIR} )

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2017-05-28 07:20 GMT
Find Nodes?
    Voting Booth?