On Jul 28, perl.org said: >On Wed, 28 Jul 2004 14:04:26 -0400 (EDT), Jeff 'japhy' Pinyan wrote >> On Jul 28, perl.org said: >> >> I would use File::Basename so that I can be sure it works on all >> platforms. What is your take on files with multiple extensions, like >> program.pl.bak or jeff.pinyan.txt? > >Excellent point about basename - I knew of the module, not sure why I didn't >use it. For multi-extension files (which there shouldn't be, it's a website) >I just want the last extension. Now to find out which basename returns...
Here's one approach; use File::Basename; my @sorted = map +(split /\0/, $_, 3)[2], sort map lc((fileparse($_, qr/\.[^.]*$/))[2] . "\0$_") . "\0$_", glob "*"; This is a Guttman-Rosler Transform. Unlike a Schwartzian Transform that creates datastructures, a GRT creates strings that go directly to sort(), which is faster than supplying sort() with some sorting function. The strings created look like this: lowercase ext \0 lowercase filename \0 original filename I'm using NULLs because they sort lower than any other character. They're useful here to make sure shorter extensions and filenames are sorted "earlier" than longer extensions and filenames that start the same way. What I mean is that ".htm" should come before ".html", and no matter how the filenames look, this sorting mechanism will ensure that. It might look messy, but that's the price you pay. -- Jeff "japhy" Pinyan % How can we ever be the sold short or RPI Acacia Brother #734 % the cheated, we who for every service http://japhy.perlmonk.org/ % have long ago been overpaid? http://www.perlmonks.org/ % -- Meister Eckhart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>