in reply to Sorting Directory and Filenames
this code should do it:
#!/usr/bin/perl use strict; use warnings; use File::Basename; my @files; while(<>) { chomp; push @files, $_; } sub fcmp { my $res = dirname($a) cmp dirname($b); $res = basename($a) cmp basename($b) unless $res; return $res; } my @sorted = sort fcmp @files; print "$_\n" for @sorted;
Update: note that array should contain only filenames, if there are directory names it will not work correctly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting Directory and Filenames
by Anonymous Monk on Jan 10, 2009 at 18:22 UTC | |
by ikegami (Patriarch) on Jan 10, 2009 at 19:13 UTC |