Thanks Jeff, thanks Rob.
I used your solution Jeff and it's working a treat.
Cheers,
Nigel
Rob Dixon wrote:
Nigel Peck wrote:
Hi,
I have a list containing the names of all items in a directory. I want
to sort it by non-directories first and then directories, with a
secondary sort in alphabetical order.
I currently have:
--------------------------------
my @items = sort {
my $a_path = $args->{directory_from} . '\\' . $a;
my $b_path = $args->{directory_from} . '\\' . $b;
( -d $a_path ) ? 1 : 0;
} readdir $directory;
--------------------------------
which gets me the non-directories first and directories after but not
in alphabetical order.
I don't want to rely on the alphabetical ordering from the readdir as
I believe that Perl's sort does not guarantee to maintain ordering in
future releases?
Can't get my head round this, please help! :)
Cheers,
Nigel
my @items = sort {
my $a_path = $args->{directory_from} . '\\' . $a;
my $b_path = $args->{directory_from} . '\\' . $b;
-d $b_path cmp -d $a_path
or
$a cmp $b;
} readdir $directory;
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/