[Pdx-pm] tilde in paths

Joshua Keroes jkeroes at eli.net
Thu Nov 20 15:55:36 CST 2003

On Nov 20, 2003, at 1:54 PM, Thomas Keller wrote:

> Greetings,
> Forgive my laziness for not searching for the answer to this. But does 
> someone off the top of their head know how to open a file with a tilde 
> in the path?

Found in /usr/local/perl581/lib/5.8.1/pods/perlfaq5.pod
        How can I translate tildes (~) in a filename?

        Use the <> (glob()) operator, documented in perlfunc.  Older 
        of Perl require that you have a shell installed that groks 
        Recent perl versions have this feature built in. The File::KGlob 
        (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} )

Have a nice day. :-)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Joshua Keroes.vcf
Type: text/directory
Size: 363 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/pdx-pm-list/attachments/20031120/e6e6ac64/JoshuaKeroes.bin
-------------- next part --------------

More information about the Pdx-pm-list mailing list