Click here to get back home

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

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
FAQ 5.14 How can I translate tildes (~) in a filename? PerlFAQ Server 06-08-2008
Posted by PerlFAQ Server on June 8, 2008, 3:03 am
Please log in for more thread options
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

--------------------------------------------------------------------

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


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



--------------------------------------------------------------------

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.

If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.

Posted by Michael Carman on June 8, 2008, 10:19 am
Please log in for more thread options
PerlFAQ Server wrote:
> Older versions of Perl require that you have a shell installed that
> groks tildes. Recent perl versions have this feature built in.

Can anyone here quantify "older" and "recent?"

-mjc

Posted by Peter J. Holzer on June 8, 2008, 10:46 am
Please log in for more thread options
> PerlFAQ Server wrote:
>> Older versions of Perl require that you have a shell installed that
>> groks tildes. Recent perl versions have this feature built in.
>
> Can anyone here quantify "older" and "recent?"

I *think* this was changed in perl 5.6.0.

        hp

Posted by Ben Morrow on June 8, 2008, 6:07 pm
Please log in for more thread options

> > PerlFAQ Server wrote:
> >> Older versions of Perl require that you have a shell installed that
> >> groks tildes. Recent perl versions have this feature built in.
> >
> > Can anyone here quantify "older" and "recent?"
>
> I *think* this was changed in perl 5.6.0.

So does perldoc File::Glob, and git://utsl.gen.nz/perl says that
5.005_04 still called csh (or other things, on other platforms).

Ben

--
"Faith has you at a disadvantage, Buffy."
"'Cause I'm not crazy, or 'cause I don't kill people?"
"Both, actually."
[ben@morrow.me.uk]

Posted by brian d foy on June 10, 2008, 12:00 pm
Please log in for more thread options

> PerlFAQ Server wrote:
> > Older versions of Perl require that you have a shell installed that
> > groks tildes. Recent perl versions have this feature built in.
>
> Can anyone here quantify "older" and "recent?"

Thanks for pointed this out. I've noticed too much of the FAQ assumes
that you're reading it the same day it was written, so any references
to timeliness need to go away. :0

Similar ThreadsPosted
FAQ 5.12: How can I translate tildes (~) in a filename? December 22, 2004, 12:03 am
FAQ 5.12 How can I translate tildes (~) in a filename? March 1, 2005, 12:03 pm
FAQ 5.13 How can I translate tildes (~) in a filename? April 20, 2005, 11:03 am
FAQ 5.13 How can I translate tildes (~) in a filename? July 6, 2005, 4:03 pm
FAQ 5.13 How can I translate tildes (~) in a filename? September 18, 2005, 4:03 pm
FAQ 5.13 How can I translate tildes (~) in a filename? November 23, 2005, 5:03 am
FAQ 5.13 How can I translate tildes (~) in a filename? March 7, 2006, 3:03 pm
FAQ 5.13 How can I translate tildes (~) in a filename? April 24, 2006, 9:03 am
FAQ 5.13 How can I translate tildes (~) in a filename? July 27, 2006, 9:03 am
FAQ 5.13 How can I translate tildes (~) in a filename? November 21, 2006, 3:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap