I have a list of files I want to case-insensitive sort by extension, files with no extension appearing first. It should handle both Windows and Unix directory separators. I think I have working code, but I am interested in the various syntax for this one - there MUST be a better way than my feeble attempt:
use strict; my @input = ( '/path/to/file/with.ext', '/path/to/file/with.htm', '/path/to/file/without', '/path/to/file/with.eml', '/path/to/file/with.pdf' ); my @output = sort { my $ex1 = ''; my $ex2 = ''; if ( $a =~ m#[^\\/]\.([^\\/]+)$# ) { $ex1 = $1; } if ( $b =~ m#[^\\/]\.([^\\/]+)$# ) { $ex2 = $1; } return( lc( $ex1 ) cmp lc( $ex2 )); } @input; print join( $/, @output ); C:\temp>sortext.pl /path/to/file/without /path/to/file/with.eml /path/to/file/with.ext /path/to/file/with.htm /path/to/file/with.pdf -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>